Skip to main content

Function: wireAudioSession()

function wireAudioSession(player: AudioSessionPlayerLike, options?: WireAudioSessionOptions): Unsubscribe;

Defined in: packages/audio-session/src/wire.ts:126

Connect an audio session to a player: duck/pause on interruption, restore or resume when it ends, pause when the headphones are yanked.

Activating the session before play() stays the app's job — this helper only reacts to what the OS reports. It is entirely event-driven; there are no timers or polling anywhere in it.

Resume is owed only for pauses this helper performed on a playing player. Both platforms report interruptions to whoever holds focus even while that app's player sits paused (see AudioSessionPlayerLike.isPlaying), and the resume hint on the way out (AUDIOFOCUS_GAIN after a transient loss, AVAudioSession's .shouldResume) means "the system permits resuming" — never "you were playing". A player that implements isPlaying (and ideally onStateChange) gets the full guarantee; one that implements neither keeps the old behaviour of resuming after every transient interruption, user pause or not, because the helper has nothing to consult.

Parameters

ParameterType
playerAudioSessionPlayerLike
optionsWireAudioSessionOptions

Returns

Unsubscribe

a function that removes every listener it installed. It does not deactivate the session (the app may still be playing) and does not undo a duck in progress — call it while idle if that matters.