Skip to content

fix(player): double-buffer audio for seamless track transitions#13

Open
andronedev wants to merge 1 commit into
developfrom
feature/betterbgaudio
Open

fix(player): double-buffer audio for seamless track transitions#13
andronedev wants to merge 1 commit into
developfrom
feature/betterbgaudio

Conversation

@andronedev

Copy link
Copy Markdown
Owner

Two HTMLAudioElements alternate as the active player; the next track is preloaded on the inactive one and a transition just swaps which element drives state. The MediaSession-attached element is no longer destroyed between tracks (no kWebMediaPlayerDestroyed -> kPlay cycle), which fixes:

  • Android notification disappearing for ~2s between tracks
  • Auto-advance failing in background (Chromium Android / Vanadium / GrapheneOS) because the autoplay gesture token was invalidated by the MediaSession orphaning during src reassignment

Falls back to in-place src reassignment when the next track wasn't prefetched (first play, random pick, user jump). Listeners attached to both elements with an "el !== activeAudio()" guard so the prefetch element never drives store state.

Two HTMLAudioElements alternate as the active player; the next track is
preloaded on the inactive one and a transition just swaps which element
drives state. The MediaSession-attached element is no longer destroyed
between tracks (no kWebMediaPlayerDestroyed -> kPlay cycle), which fixes:

- Android notification disappearing for ~2s between tracks
- Auto-advance failing in background (Chromium Android / Vanadium /
  GrapheneOS) because the autoplay gesture token was invalidated by
  the MediaSession orphaning during src reassignment

Falls back to in-place src reassignment when the next track wasn't
prefetched (first play, random pick, user jump). Listeners attached
to both elements with an "el !== activeAudio()" guard so the prefetch
element never drives store state.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant