Skip to content

AudioOutputSession

One playback session. Sessions of one service are independent: stopping one does not disturb another.

The normal path is write() for each chunk, then drain(), then stop(); a provider’s cancel path is stop().

A session ends once: by stop(), or by the system taking the output away (an interruption, the output stopping), which ends it with Unavailable and details.code audio_output_interrupted.

drain(): Promise<void>

Resolves when everything written has played. After stop(), returns at once without effect; after the system ended the session, throws its error.

Promise<void>


firstAudioMs(): number | undefined

Milliseconds from the start of open() (the instant it was called, before the output is built or started) to the first frame the host observed leaving the output; undefined until then. A provider reports firstAudioMs = (instant before open() was called − receivedAt) + session.firstAudioMs(), so a slow open is counted once.

number | undefined


stop(): void

Ends the session now: discards buffered audio and releases the output. Idempotent, and nothing renders after it.

void


write(samples): Promise<void>

Hands samples to the host. Resolves once the host has buffered them, so a caller that awaits each write is paced by the output (backpressure). The first write is the first possible audible effect. After stop(), returns at once without effect; after the system ended the session, throws its error.

Int16Array

Promise<void>