Interface: AudioSessionPlayerLike
Defined in: packages/audio-session/src/wire.ts:12
The only thing wireAudioSession needs from a player.
Structural on purpose — our Player, react-native-track-player, expo-audio
and a hand-rolled fake all satisfy it. This package must never import
@afkcodes/timbre-player.
Methods
getVolume()
getVolume(): number;
Defined in: packages/audio-session/src/wire.ts:17
Returns
number
isPlaying()?
optional isPlaying(): boolean;
Defined in: packages/audio-session/src/wire.ts:35
Whether the player is currently playing (not paused), if it can say.
This is what makes a user's pause sacred. Both platforms report
interruptions to a session that holds focus regardless of whether audio
is actually playing — Android delivers AUDIOFOCUS_LOSS_TRANSIENT /
AUDIOFOCUS_GAIN to the focus holder even while its player sits paused,
and AVAudioSession's interruption .ended carries .shouldResume with
exactly the same blindness. Without this method the helper cannot tell
"we paused the player for the interruption" apart from "the user had
already paused it", and resuming in the second case starts music the user
explicitly stopped (the paused-then-Instagram-reel bug, #45).
When absent, the helper falls back to claiming every interruption pause — the pre-#45 behaviour — because guessing "not playing" would break resume-after-call for players that simply cannot report.
Returns
boolean
onStateChange()?
optional onStateChange(listener: (state: {
playing: boolean;
}) => void): Unsubscribe;
Defined in: packages/audio-session/src/wire.ts:49
Subscribe to state changes, if the player supports it. Only playing is
read.
Why isPlaying alone is not enough: play()/pause() on a real
player are asynchronous (an mpv property round-trips through the native
event loop), so for a few milliseconds after this helper resumes a player,
isPlaying() still answers false. Interruptions genuinely arrive inside
that window — Instagram flaps transient focus loss/gain 14 ms apart
(measured, #45) — and a stale false there would make the helper refuse a
pause claim it is entitled to. The subscription is what lets the helper
know when its own play() has actually landed.
Parameters
| Parameter | Type |
|---|---|
listener | (state: { playing: boolean; }) => void |
Returns
pause()
pause(): void;
Defined in: packages/audio-session/src/wire.ts:14
Returns
void
play()
play(): void;
Defined in: packages/audio-session/src/wire.ts:13
Returns
void
setVolume()
setVolume(volume: number): void;
Defined in: packages/audio-session/src/wire.ts:16
Volume in the player's own scale; only ever fed values read back from getVolume, or duckVolume.
Parameters
| Parameter | Type |
|---|---|
volume | number |
Returns
void