In my application, when I start my audio call/audio broadcast I have request the audio manager for audio focus.
audioManager.requestAudioFocus(null,audioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT| AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
If the user presses Home and navigates to another media application, and then if they play any media, that file is also played at low volume. The person receiving the call can also hear that media sound file.
When my audio call is in progress, if the user tries to play any audio resources, how do I tell the audio manager to give the preference to my application only?
What you’re describing is the default behavior on Android (I believe). That being said, you should be able to do what you’re hoping. The Android SDK allows you to set a single stream type as solo – causing all other streams to be muted. To do this, you should use the
AudioManagersetStreamSolo()call:audioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);You’ll want to do this when playback begins, then set the stream solo to false when playback ends or your Activity finishes. Let me know if that does the trick.
Couple of resources that might be helpful: