Skip to main content

Interface: AudioSessionApi

Defined in: packages/audio-session/src/types.ts:63

The public singleton surface.

Declared as an interface (rather than inferred from the implementation) so that tests, and anyone wiring a different backend, can substitute a fake.

Methods

activate()

activate(): Promise<boolean>;

Defined in: packages/audio-session/src/types.ts:79

Request the session/focus. Resolves false when the OS refuses — callers must not start playback in that case. A rejection means the call itself was wrong (or the media server is broken), never "denied"; see RnMediaAudioSession.activate for the exact iOS error codes each side takes.

Returns

Promise<boolean>


addListener()

addListener<K extends keyof AudioSessionEventMap>(event: K, listener: (payload: AudioSessionEventMap[K]) => void): Unsubscribe;

Defined in: packages/audio-session/src/types.ts:95

Subscribe to one of the three event streams.

becomingNoisy and routeChange are delivered from the moment you subscribe on both platforms. interruption additionally requires an outstanding focus request on Android — see RnMediaAudioSession.addInterruptionListener.

Type Parameters

Type Parameter
K extends keyof AudioSessionEventMap

Parameters

ParameterType
eventK
listener(payload: AudioSessionEventMap[K]) => void

Returns

Unsubscribe


configure()

configure(config: AudioSessionConfig): Promise<void>;

Defined in: packages/audio-session/src/types.ts:71

Apply an AudioSessionConfig (or a preset) to the OS session.

Applies immediately on iOS; takes effect at the next activate on Android. Configure before activating and the two agree — see RnMediaAudioSession.configure for why the models differ.

Parameters

ParameterType
configAudioSessionConfig

Returns

Promise<void>


deactivate()

deactivate(): Promise<void>;

Defined in: packages/audio-session/src/types.ts:86

Release the session/focus.

Rejects on iOS if audio is still playing (AVAudioSessionErrorCode.isBusy); cannot reject on Android. Pause the player first.

Returns

Promise<void>