[expo-audio] Surface audio sampling on AudioPlaylist (setAudioSamplingEnabled + audioSampleUpdate)
A
Aram Mamian
AudioPlayer
already ships PCM sampling — isAudioSamplingSupported
,setAudioSamplingEnabled(enabled)
, and the audioSampleUpdate
event.AudioPlaylist
has none of it: its entire event map is playlistStatusUpdate
and
trackChanged
.The ask: mirror those onto
AudioPlaylist
, emitting for whichever track iscurrent (
currentIndex
is already tracked and surfaced).Use case — a hands-free voice assistant. TTS clips play through
AudioPlaylist
because one queue gives synthesis/playback overlap, ordering, and a single
stop/kill switch in one place. The UI has a presence indicator that should pulse
with the assistant's actual voice, but with no sampling on the playlist it has
to run off a synthetic timer instead. The alternatives are adding a native
audio dependency, or moving playback to individual
AudioPlayer
s and rebuildingthe queue/skip machinery — neither is proportionate to needing an amplitude
number.
It looks small on both platforms (read against 57.0.4):
- Android: AudioPlayersources its samples fromVisualizer(ref.audioSessionId)
in
createVisualizer()
. AudioPlaylist
extends the same BaseAudioPlayer
andso has the same
ref.audioSessionId
, and Visualizer
binds to the audiosession rather than the media item — so track changes need no special handling.
Lifting
samplingEnabled
+ createVisualizer()
+ sendAudioSampleUpdate()
into
BaseAudioPlayer
would give both classes the feature at once.- iOS: AudioTapProcessoris initialised with anAVPlayer, andAudioPlaylist
is a
SharedRef<AVQueuePlayer>
— already an AVPlayer
. The tap attaches toplayer.currentItem
's audio mix, so the only additional piece is re-installingit on track change, which the playlist already observes.
Happy to put up a PR if that would be welcome.