Skip to main content
Version: 7.6.0

Audio Control Management on Android

Overview

Android allows multiple apps to play audio concurrently, but this can lead to a disruptive user experience due to mixed audio streams. To enhance user experience, Android offers an API for apps to control audio focus, ensuring only one app possesses audio focus, thus delivering a more favorable user experience.

This section details how react-native-theoplayer addresses changes in audio focus, which is available as of version 2.12.0.

References:

Audio Focus

The react-native-theoplayer package is equipped with inherent audio focus management. It initiates an audio focus request upon the start of playback and responds to the loss of audio focus by pausing playback.

If the loss was transient, i.e. lasting only for a short while such as during an incoming phone call, the player will regain audio focus afterward and play-out while resume.

Audio "ducking"

When another app seeks audio focus, it can optionally indicate that the current audio focus holder can lower its playback volume to continue playing (AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK). The new focus holder does not require other apps to be silent. This behavior is known as "ducking."

In summary:

EventAction
AUDIOFOCUS_LOSS, AUDIOFOCUS_LOSS_TRANSIENTPause play-out
AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCKLower volume
AUDIOFOCUS_GAINResume play-out or restore volume

Audio Becoming Noisy

When headphones are unplugged or a Bluetooth device is disconnected, the audio stream automatically reroutes to the device's built-in speaker. This can lead to an abrupt increase in volume, which is an undesired outcome.

The "Audio Becoming Noisy" situation is also managed by pausing playback for the react-native-theoplayer package.