Skip to content

feat(playback): sync playback state across devices - #14825

Open
dylanjeffers wants to merge 1 commit into
mainfrom
feat/playback-state-sync
Open

dylanjeffers wants to merge 1 commit into
mainfrom
feat/playback-state-sync

Conversation

@dylanjeffers

Copy link
Copy Markdown
Contributor

Summary

Client side of cross-device playback sync: play on desktop/web, open the app on your phone (or vice versa) and the same track and queue are cued up, ready to resume where you left off.

Depends on AudiusProject/api#1089 (the playback-state endpoints). Everything is behind a new playback_state_sync feature flag — off in production, on in development — so this is safe to merge before the API ships. The flag still needs creating in Optimizely.

How it works

  • Snapshot format (common/store/playback/snapshot.ts): versioned wire format with queue (hash ids, source/collection/behavior carried through), index, position, playing flag, shuffle (incl. original order so un-shuffle works on the other device), repeat and rate. Anything read from the server is validated and rejected wholesale if malformed.
  • Publish (web/src/common/store/playback/syncSagas.ts, shared by web, desktop and native): debounced on playback/queue changes plus a 30s heartbeat while playing. Stable per-install device id in local storage.
  • Restore: on startup and on tab focus / app foreground, if nothing is playing locally and the server holds a snapshot this session hasn't seen, the queue is restored cued-up and paused. Local playback is never interrupted.
  • Resume: new resume field on the playback slice. A bare play with a pending resume loads the cued track at the saved position; skipping, picking another track, etc. clears it.
  • Web/desktop: the desktop play bar shows the pending resume position before play.
  • Mobile: a restored queue loads into the track player paused instead of auto-playing; foreground triggers a sync.

Not in this PR

  • Live handoff: starting playback here does not pause the other device, and there is no device picker / remote control. Needs a realtime channel (likely the comms websocket).
  • Mobile-web play bar and the native scrubber don't show the saved position before play (native does a best-effort seek on load).
  • No flush on tab close, so position can be up to ~30s stale.
  • Queues are trimmed to 50 tracks behind / 200 ahead of the current one.

Testing

  • Unit tests: snapshot round trip / validation and hydrate/resume reducer behavior (common), publish + restore saga behavior (web).
  • Typecheck clean on web and mobile; lint clean on changed files.
  • Not yet tested end to end: the API endpoints aren't deployed, so the clients have not run against a real backend, and the native changes have not been exercised on a simulator or device. Needs a manual pass on web, iOS and Android once the API PR is live (with the flag on).

🤖 Generated with Claude Code

Publishes this device's playback snapshot (queue, index, position,
shuffle/repeat, rate) to the API on playback changes and on a heartbeat
while playing, and restores the latest snapshot on startup and on
focus/foreground when nothing is playing locally. A restored queue is
cued up paused; pressing play loads the track at the saved position.

Shared saga covers web, desktop and native mobile. Gated behind the
playback_state_sync feature flag (off in production).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 81faa27

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant