Audio focus improvements

A media or game app that uses audio focus shouldn't play audio after it loses focus. Starting with Android 12, the framework enforces this behavior. When an app requests audio focus while another app has the focus and is playing, the framework forces the playing app to fade out. The addition of the fade-out provides a smoother transition when going from one app to another.

This fade out behavior happens when the following conditions are met:

The audio system fades out the first app. At the end of the fade out, the system notifies the first app of focus loss. Its players remain muted until the app requests audio focus again.

Existing audio focus behaviors

You should also be aware of these other cases that involve a switch in audio focus.

Automatic ducking

Automatic ducking (temporarily reducing the audio level of one app so that another can be heard clearly) was introduced in Android 8.

By having the framework implement ducking, the developer doesn't have to implement ducking in their app.

Automatic ducking also occurs when an audio notification grabs the focus from a playing app. The start of the notification playback is synchronized with the end of the ducking ramp.

Automatic ducking happens when the following conditions are met:

  • The first, currently playing app must:

  • A second app requests audio focus with [AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK](/reference/android/media/AudioManager#AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK.

The audio system ducks all the active players of the first app while the second app has focus. When the second app abandons focus, it unducks them. The first app is not notified when it loses focus, therefore, it doesn’t have to do anything.

Note that automatic ducking is not performed when listening to speech content, because the user might miss some of the program. For example, if you duck playback while giving driving directions.

Mute incoming phone calls

Some apps don't behave properly and continue playing during phone calls. This forces the user to find and mute or quit the offending app in order to hear their call. This feature ensures that no app continues to play when there is an incoming call. It is invoked when an app meets these conditions:

  • has usage AudioAttributes.USAGE_MEDIA or AudioAttributes.USAGE_GAME
  • successfully requested audio focus (any focus gain) and is playing audio

If an app continues playing during the call, its playback is muted until the call ends. However, if an app starts playing during the call, that player is not muted as this is assumed to be an intentional action by the user.