Skip to main content

AudioContext

Cross-platform configuration for native audio session and focus behavior.

Unset fields (None) are filled in when the context is applied on mobile: route as SYSTEM, focus as GAIN, and respect_silence / stay_awake as False.

Note

On iOS, audio context cannot be handled for each player individually, so setting this property on an Audio instance applies the context globally for the app.

Meaningful mainly on Android and iOS; desktop and web ignore it.

Properties

Properties​

focusclass-attributeinstance-attribute​

focus: AudioContextFocus | None = None

The audio focus mode (GAIN, DUCK_OTHERS, or MIX_WITH_OTHERS).

If unset (None), mobile platforms behave as GAIN.

respect_silenceclass-attributeinstance-attribute​

respect_silence: bool | None = None

Whether the audio should be muted when the device is in silent/ringer mode.

If unset (None), mobile platforms behave as False (audio can play while the device is silenced).

Warning

Due to iOS platform limitations, setting this to True cannot be combined with DUCK_OTHERS, MIX_WITH_OTHERS, or SPEAKER.

routeclass-attributeinstance-attribute​

route: AudioContextRoute | None = None

The audio output route (SYSTEM, SPEAKER, or EARPIECE).

If unset (None), mobile platforms behave as SYSTEM.

stay_awakeclass-attributeinstance-attribute​

stay_awake: bool | None = None

Whether to keep the device awake (acquire a wake lock) while playing audio.

If unset (None), mobile platforms behave as False.