Manage audio focus (Android)

Configure how playback responds to audio interruptions from other applications and system activities

Audio focus allows an Android application to manage playback when another application or system activity requires audio output. The JWX Android SDK supports optional audio focus handling to pause playback during interruptions and resume playback when appropriate.

Audio focus handling is disabled by default. Applications that already manage audio focus can continue using their existing implementations.



Enable audio focus handling

Use ExoPlayerSettings to enable audio focus handling.

player.getExoPlayerSettings().setAudioFocusHandlingEnabled(true);

When enabled, the SDK requests audio focus during audible playback while the player is visible, in Picture-in-Picture mode, or playing in the background with background audio enabled.

Muted playback and Chromecast sessions do not request local audio focus.



Audio focus behavior

When audio focus handling is enabled, the player pauses when audio focus is lost. Playback can resume after a temporary interruption, provided the viewer or application has not independently changed playback. If another app takes audio focus permanently, such as another media app starting playback, the player stays paused.

On Android 8.0 and later, the operating system may temporarily reduce playback volume without pausing.


Regardless of whether audio focus handling is enabled, the player pauses when wired headphones or a Bluetooth audio device disconnects.

Audio focus is managed per player. If more than one player in your app has audio focus handling enabled, starting playback in one pauses the others.

For detailed behavior, see setAudioFocusHandlingEnabled(boolean) in the Android SDK reference.


Monitor audio focus changes

To monitor audio focus changes, register an AudioFocusListener using setAudioFocusListener().

The listener receives AudioFocusChange callbacks while audio focus handling is enabled.

Pauses caused by audio focus loss are also reported through the pause event with PauseReason.AUDIO_INTERRUPTION.


Did this page help you?
© 2007- Longtail Ad Solutions, Inc.