Skip to main content

AudioFocus

How an Audio shares audio with other audio on mobile platforms.

On Android, focus belongs to each player, so an Audio competes with others of the same app as it does with other apps. On iOS, it only decides how the app treats other apps, because all audio of an app always plays together.

Inherits: enum.Enum

Properties

  • DUCK_OTHERS - Lowers the volume of other apps' audio while this audio plays.
  • GAIN - Plays as the only audio.
  • MIX_WITH_OTHERS - Plays over other audio, which isn't affected.

Properties​

DUCK_OTHERSclass-attributeinstance-attribute​

Lowers the volume of other apps' audio while this audio plays.

On Android, another Audio of the same app keeps playing at its own volume. An app can choose to pause its audio instead of having it lowered, which some do for speech. Other apps' audio also stays lowered while this audio is paused, until it is released or finishes after resuming.

On iOS, other apps' audio returns to its volume once no Audio of the app is playing. An Audio that something else paused still counts as playing until it is paused or released, or finishes after resuming.

Warning

On iOS, can't be combined with AudioContext.respect_silence.

GAINclass-attributeinstance-attribute​

Plays as the only audio.

On Android, any other audio that is playing, including another Audio of the same app, is paused and doesn't resume on its own. On iOS, other apps' audio is interrupted and doesn't resume on its own. If the app has already played audio, this happens as soon as the context is applied, even before this audio plays.

Best for music players.

MIX_WITH_OTHERSclass-attributeinstance-attribute​

Plays over other audio, which isn't affected.

On Android, nothing else pauses this audio, though Android still mutes it while a phone call is ringing, during which its position keeps advancing.

Best for short sound effects that shouldn't lower the volume of other apps.

Warning

On iOS, can't be combined with AudioContext.respect_silence.