contexts/playback.tsx was ~1,380 lines that mixed native playlist sync, progress persistence, the queue API and three contexts. It also relied on timers and polling instead of player events: a 150 ms setTimeout to suppress track-change events, a 250 ms poll for Siri donation, and a 100 ms poll in waitForPlaybackReady.
Changes
hooks/use-native-playlist-sync.ts keeps the native AudioPlaylist in sync with the queue and reports its status back.
hooks/use-progress-persistence.ts restores the saved position and saves it while playing, on pause, and when the app goes to the background.
contexts/playback.tsx is now a thin provider (~740 lines) holding the store wiring, the queue API and the contexts.
Track-change suppression: each sync records where it left the native player (index, current song, history length). A trackChanged event is ignored when the player's live index still matches that record, or while a queue change is still being applied. This replaces the 150 ms timer. Native currentIndex reads and edits are synchronous on both platforms, so the record matches the player.
Readiness: waitForSong keeps a map of pending promises keyed by song ID. playlistStatusUpdate, trackChanged and each sync settle it, and a store subscription rejects it when the queue moves on. Siri donation and waitForPlaybackReady both use it. The 20 s timeout and the error messages are unchanged.
The play* / play*Shuffled pairs for album, artist and playlist are built from one table.
Fix (also broken on main): a restored queue showed 0:00 until Play, and playback started before the song loaded (Play right after launch, a Siri resume) began at 0:00 and then jumped. The restore seek is now queued as soon as the song becomes current, the saved position shows right away, and play() waits until a pending seek lands. This also covers rebuilding the player after a stream-quality change.
Apart from that fix, behavior is unchanged.
Testing
pnpm typecheck passes.
iOS (iPhone Duo simulator): restoring the queue on cold start (paused at the saved position, Play continues from there; with temporary logging, the native player's first playing status was at the saved position, never 0:00, including when playback was requested before the song loaded), play/pause, Previous (restart, then back one track), Next, seek, the next track starting when one ends, play album, play from a song in an album, shuffle while playing, and jumping to a song in the queue.
One stall seen once and not reproduced: a track stopped 4 s before its end while the UI showed it playing. After a relaunch it resumed and moved on to the next track normally.
Not tested: Siri intents and lock-screen controls (can't trigger them on the simulator), and Android (the emulator was in use).
Changes by Claude Opus 5.5 (claude-opus-5-5) in Claude Code, running in T3 Code.
`contexts/playback.tsx` was ~1,380 lines that mixed native playlist sync, progress persistence, the queue API and three contexts. It also relied on timers and polling instead of player events: a 150 ms `setTimeout` to suppress track-change events, a 250 ms poll for Siri donation, and a 100 ms poll in `waitForPlaybackReady`.
## Changes
- `hooks/use-native-playlist-sync.ts` keeps the native `AudioPlaylist` in sync with the queue and reports its status back.
- `hooks/use-progress-persistence.ts` restores the saved position and saves it while playing, on pause, and when the app goes to the background.
- `contexts/playback.tsx` is now a thin provider (~740 lines) holding the store wiring, the queue API and the contexts.
- Track-change suppression: each sync records where it left the native player (index, current song, history length). A `trackChanged` event is ignored when the player's live index still matches that record, or while a queue change is still being applied. This replaces the 150 ms timer. Native `currentIndex` reads and edits are synchronous on both platforms, so the record matches the player.
- Readiness: `waitForSong` keeps a map of pending promises keyed by song ID. `playlistStatusUpdate`, `trackChanged` and each sync settle it, and a store subscription rejects it when the queue moves on. Siri donation and `waitForPlaybackReady` both use it. The 20 s timeout and the error messages are unchanged.
- The `play*` / `play*Shuffled` pairs for album, artist and playlist are built from one table.
- Fix (also broken on `main`): a restored queue showed 0:00 until Play, and playback started before the song loaded (Play right after launch, a Siri resume) began at 0:00 and then jumped. The restore seek is now queued as soon as the song becomes current, the saved position shows right away, and `play()` waits until a pending seek lands. This also covers rebuilding the player after a stream-quality change.
Apart from that fix, behavior is unchanged.
## Testing
- `pnpm typecheck` passes.
- iOS (iPhone Duo simulator): restoring the queue on cold start (paused at the saved position, Play continues from there; with temporary logging, the native player's first playing status was at the saved position, never 0:00, including when playback was requested before the song loaded), play/pause, Previous (restart, then back one track), Next, seek, the next track starting when one ends, play album, play from a song in an album, shuffle while playing, and jumping to a song in the queue.
- One stall seen once and not reproduced: a track stopped 4 s before its end while the UI showed it playing. After a relaunch it resumed and moved on to the next track normally.
- Not tested: Siri intents and lock-screen controls (can't trigger them on the simulator), and Android (the emulator was in use).
---
Changes by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, running in T3 Code.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Move native playlist sync and progress persistence into their own hooks,
wait on playlist events instead of timers and polling, and build the
album/artist/playlist play actions from one table.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A paused player sends no status updates after it loads, so a restored
position waited until Play to apply and the slider showed 0:00. Seek
right away when the song is already loaded, and show the position.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The restore seek was queued only after the player loaded, so playback
requested before then (Play right after launch, a Siri resume) started
at 0:00 and jumped. Queue the seek when the song becomes current, and
hold off starting the player until a pending seek lands.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
contexts/playback.tsxwas ~1,380 lines that mixed native playlist sync, progress persistence, the queue API and three contexts. It also relied on timers and polling instead of player events: a 150 mssetTimeoutto suppress track-change events, a 250 ms poll for Siri donation, and a 100 ms poll inwaitForPlaybackReady.Changes
hooks/use-native-playlist-sync.tskeeps the nativeAudioPlaylistin sync with the queue and reports its status back.hooks/use-progress-persistence.tsrestores the saved position and saves it while playing, on pause, and when the app goes to the background.contexts/playback.tsxis now a thin provider (~740 lines) holding the store wiring, the queue API and the contexts.Track-change suppression: each sync records where it left the native player (index, current song, history length). A
trackChangedevent is ignored when the player's live index still matches that record, or while a queue change is still being applied. This replaces the 150 ms timer. NativecurrentIndexreads and edits are synchronous on both platforms, so the record matches the player.Readiness:
waitForSongkeeps a map of pending promises keyed by song ID.playlistStatusUpdate,trackChangedand each sync settle it, and a store subscription rejects it when the queue moves on. Siri donation andwaitForPlaybackReadyboth use it. The 20 s timeout and the error messages are unchanged.The
play*/play*Shuffledpairs for album, artist and playlist are built from one table.Fix (also broken on
main): a restored queue showed 0:00 until Play, and playback started before the song loaded (Play right after launch, a Siri resume) began at 0:00 and then jumped. The restore seek is now queued as soon as the song becomes current, the saved position shows right away, andplay()waits until a pending seek lands. This also covers rebuilding the player after a stream-quality change.Apart from that fix, behavior is unchanged.
Testing
pnpm typecheckpasses.Changes by Claude Opus 5.5 (
claude-opus-5-5) in Claude Code, running in T3 Code.🤖 Generated with Claude Code