Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ export class Queue implements TrackQueueRef {
const e = event as { type: 'SEEK'; time: number };
this._trackAt(context.currentTrackIndex)?.seek(e.time);
},
seekCurrentToZero: ({ context }) => {
this._trackAt(context.currentTrackIndex)?.seek(0);
seekCurrentToStartTime: ({ context, event }) => {
const e = event as { type: 'GOTO'; startTime?: number };
this._trackAt(context.currentTrackIndex)?.seek(e.startTime ?? 0);
},
scheduleGapless: ({ context }) => {
this._tryScheduleGapless(context.currentTrackIndex);
Expand Down Expand Up @@ -278,12 +279,12 @@ export class Queue implements TrackQueueRef {
this._actor.send({ type: 'PREVIOUS' });
}

gotoTrack(index: number, playImmediately = false): void {
gotoTrack(index: number, playImmediately = false, startTime?: number): void {
if (index < 0 || index >= this._tracks.length) return;
this.onDebug(
`gotoTrack(${index}, playImmediately=${playImmediately}) queueState=${this._actor.getSnapshot().value} curIdx=${this._actor.getSnapshot().context.currentTrackIndex}`
`gotoTrack(${index}, playImmediately=${playImmediately}, startTime=${startTime}) queueState=${this._actor.getSnapshot().value} curIdx=${this._actor.getSnapshot().context.currentTrackIndex}`
);
this._actor.send({ type: 'GOTO', index, playImmediately });
this._actor.send({ type: 'GOTO', index, playImmediately, startTime });
}

seek(time: number): void {
Expand Down
16 changes: 10 additions & 6 deletions src/machines/queue.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type QueueEvent =
| { type: 'TOGGLE' }
| { type: 'NEXT' }
| { type: 'PREVIOUS' }
| { type: 'GOTO'; index: number; playImmediately?: boolean }
| { type: 'GOTO'; index: number; playImmediately?: boolean; startTime?: number }
| { type: 'SEEK'; time: number }
| { type: 'SET_VOLUME'; volume: number }
| { type: 'ADD_TRACK' }
Expand Down Expand Up @@ -113,7 +113,7 @@ export function createQueueMachine(initialContext: QueueContext) {
playCurrent: () => {},
pauseCurrent: () => {},
seekCurrent: () => {},
seekCurrentToZero: () => {},
seekCurrentToStartTime: () => {},
scheduleGapless: () => {},
cancelScheduledGapless: () => {},
cancelAndRescheduleGapless: () => {},
Expand Down Expand Up @@ -151,6 +151,7 @@ export function createQueueMachine(initialContext: QueueContext) {
'deactivateCurrent',
'cancelAllGapless',
'gotoTrackIndex',
'seekCurrentToStartTime',
'activateAndPlayCurrent',
'notifyStartNewTrack',
'updateMediaSessionMetadata',
Expand All @@ -163,7 +164,7 @@ export function createQueueMachine(initialContext: QueueContext) {
'deactivateCurrent',
'cancelAllGapless',
'gotoTrackIndex',
'seekCurrentToZero',
'seekCurrentToStartTime',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply the start time before immediate playback

When playImmediately is true, every guarded GOTO branch calls activateAndPlayCurrent without calling seekCurrentToStartTime; the new seek action is only present in the non-immediate fallback branches. Consequently, gotoTrack(2, true, 30) starts track 2 at its existing/default position rather than at 30 seconds. Add the seek after gotoTrackIndex and before activateAndPlayCurrent in each play-immediately branch.

Useful? React with 👍 / 👎.

'preloadAhead',
],
},
Expand Down Expand Up @@ -239,6 +240,7 @@ export function createQueueMachine(initialContext: QueueContext) {
'deactivateCurrent',
'cancelAllGapless',
'gotoTrackIndex',
'seekCurrentToStartTime',
'activateAndPlayCurrent',
'notifyStartNewTrack',
'updateMediaSessionMetadata',
Expand All @@ -250,7 +252,7 @@ export function createQueueMachine(initialContext: QueueContext) {
'deactivateCurrent',
'cancelAllGapless',
'gotoTrackIndex',
'seekCurrentToZero',
'seekCurrentToStartTime',
'preloadAhead',
],
},
Expand Down Expand Up @@ -353,6 +355,7 @@ export function createQueueMachine(initialContext: QueueContext) {
'deactivateCurrent',
'cancelAllGapless',
'gotoTrackIndex',
'seekCurrentToStartTime',
'activateAndPlayCurrent',
'notifyStartNewTrack',
'updateMediaSessionMetadata',
Expand All @@ -364,7 +367,7 @@ export function createQueueMachine(initialContext: QueueContext) {
'deactivateCurrent',
'cancelAllGapless',
'gotoTrackIndex',
'seekCurrentToZero',
'seekCurrentToStartTime',
'preloadAhead',
],
},
Expand Down Expand Up @@ -421,6 +424,7 @@ export function createQueueMachine(initialContext: QueueContext) {
'deactivateCurrent',
'cancelAllGapless',
'gotoTrackIndex',
'seekCurrentToStartTime',
'activateAndPlayCurrent',
'notifyStartNewTrack',
'updateMediaSessionMetadata',
Expand All @@ -433,7 +437,7 @@ export function createQueueMachine(initialContext: QueueContext) {
'deactivateCurrent',
'cancelAllGapless',
'gotoTrackIndex',
'seekCurrentToZero',
'seekCurrentToStartTime',
'preloadAhead',
],
},
Expand Down
Loading