Recipes

Restore the Current Track and Position

Persist what is playing and resume it from the same spot after a restart.

A queue storage adapter persists the tracks and history, and sync({ syncCurrent: true }) brings queue.current back. What it does not store is the live playback position — that changes every second, so you snapshot it yourself and re-seek after replaying.

Snapshot the position

Save player.position wherever you keep durable state — a database, Redis, or the player's own typed storage. Do it on a timer and on shutdown.

save-position.ts
await (., .);

Replay on restart

After recreating the player, sync the queue to restore current, replay it, then seek to the saved position.

restore-position.ts
await ...({ : true });

const  = ..;
if () {
  await .({ :  });
  await .();
}

Seek after the track starts

Call seek() after play() — seeking is a player update against the track that is now current. If you seek before anything is playing, there is nothing to seek.