Android Development, Simply Explained

Audio focus types in Android

When using Audio Manager people often get confused between various audio focus types, which leads to people not understanding them correctly and specifying wrong audio focus values. So today I decided to write it down in a simplified format.

Here is how it works:

Basically, you have 7 types of audio focus values to choose from.

  1. AUDIOFOCUS_GAIN
  2. AUDIOFOCUS_GAIN_TRANSIENT
  3. AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
  4. AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
  5. AUDIOFOCUS_LOSS
  6. AUDIOFOCUS_LOSS_TRANSIENT
  7. AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK

Depending on what values we choose, the behavior of our app changes. Here is how each audio focus value works:

1.AUDIOFOCUS_GAIN:

Audio focus gain is generally specified when the period of time for which the audio focus is needed is uncertain and the audio focus is required for a longer period of time. Which means audio focus is required for more than 45 seconds.

Eg. When a song is to be played, we might require audio focus for a longer period of time.

2. AUDIOFOCUS_GAIN_TRANSIENT:

Audio focus gain transient is used when we require audio focus for shorter periods.

Eg. Driving directions, message received sound etc.

3. AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:

Audio focus gain transient exclusive is used when you need audio focus for a short period of time without any interruptions.

Eg. When you ask google now for an answer, you do not want any other app to interrupt it. That is you do not want it to duck or pause for other apps.

4. AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:

Audio focus gain transient may duck is used when the audio focus is required for short period of time but it is ok if some other app wants to grab the audio focus and reduce the volume of our existing app.

Eg. When the music’s playing and a notification pops up, it is ok if the volume is temporarily reduced to hear the notification sound.

5. AUDIOFOCUS_LOSS:

Audio focus loss is used to indicate the loss of audio focus for an unknown period of time, which may be a temporary loss of audio focus or a permanent loss of audio focus.

Eg. Music paused for notification (temporary loss of audio focus), when user taps the home button and quits the app in which case the audio focus is permanently lost.

6. AUDIOFOCUS_LOSS_TRANSIENT:

Audio focus loss transient is used to indicate temporary loss of audio focus. That is some other app takes over the audio focus for a short time.

7. AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:

Audio focus loss transient can duck is used to indicate temporarily lowering the volume of the existing app, for some other app to occupy the focus for a short period of time.

Eg. When some song is playing in a music player and a message pops up, the music player loses focus but does not pause or stop playing the song. Instead, it just lowers the volume of the song so that the notification sound is audible to the user.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.