Understanding Audio Focus (Part 1 / 3)
Nazmul Idris (Naz)
2401

When the phone rings (and the user hasn’t answered yet), your app should respond to a transient loss of audio focus with the option to duck (as this is being requested by the phone app). It should respond by either reducing the volume to about 20% (called ducking), or pause playback all together (if it’s a podcast or other spoken word type of app).

Unfortunately this doesn’t work for me as described in the real word. When my app is active and incoming call is received via Google Dialer, app loses audio focus with the AUDIOFOCUS_LOSS_TRANSIENT instead of AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK.

If the user accepts the call, the system will send you a loss of audio focus (without the option to duck). Your app should pause playback in response.

No, system doesn’t send it. The focus is not lost and still in the AUDIOFOCUS_LOSS_TRANSIENT state.

I’m receiving audio focus in this way:

mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener,
// Use the music stream.
AudioManager.STREAM_MUSIC,
// Request focus.
AudioManager.AUDIOFOCUS_GAIN);

Also i’ve tried AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK option

However when Skype talk is active app loses audio focus properly with the AUDIOFOCUS_LOSS type

So just because of this not working case app should to request READ_PHONE_STATE permission to detect incoming calls so it can pause playback correctly when needed.

Do you have any suggestions?