fix(web): a song on repeat is a play per listen, and a stall before play_started answers doesn't record it twice (#8071, #8072)
The events dispatcher keyed a play on the track id, so repeat-one, a one-track queue on repeat-all, or the same song twice in a row stayed one play, closed at the last loop's position and usually graded a skip. The player store now counts listens (player.listen moves whenever playback starts an item from its beginning) and the dispatcher keys a play on (track, listen). play_started's reply was adopted only while still 'playing', and nothing marked a start in flight, so a stall or pause just after starting threw the id away and the next 'playing' posted a second start, which closed the first as a skip. The dispatcher now holds the pending listen and adopts the reply whenever that listen is still current. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -65,6 +65,13 @@ let _repeat = $state<RepeatMode>('off');
|
||||
let _error = $state<string | null>(null);
|
||||
let _queueDrawerOpen = $state(false);
|
||||
|
||||
// _listen counts listens begun: it moves whenever playback starts an item
|
||||
// from its beginning (a new queue, a skip, a track ending into the next, a
|
||||
// repeat). The events dispatcher keys a play on (track, listen), so a song
|
||||
// on repeat-one, a one-track queue on repeat-all, or the same song twice in
|
||||
// a row is a play per listen rather than one long play.
|
||||
let _listen = $state(0);
|
||||
|
||||
// C1: one-shot restore position — set by restoreQueue, consumed once by
|
||||
// the layout's loadedmetadata handler so the audio element seeks to the
|
||||
// saved position after metadata loads.
|
||||
@@ -116,6 +123,7 @@ export const player = {
|
||||
get repeat() { return _repeat; },
|
||||
get error() { return _error; },
|
||||
get queueSource() { return _queueSource; },
|
||||
get listen() { return _listen; },
|
||||
get queueDrawerOpen() { return _queueDrawerOpen; }
|
||||
};
|
||||
|
||||
@@ -180,6 +188,7 @@ export function playQueue(
|
||||
_duration = 0;
|
||||
_error = null;
|
||||
_failureStreak = 0;
|
||||
_listen++;
|
||||
}
|
||||
|
||||
export function togglePlay(): void {
|
||||
@@ -200,6 +209,7 @@ export function skipNext(): void {
|
||||
_position = 0;
|
||||
_duration = 0;
|
||||
_state = 'loading';
|
||||
_listen++;
|
||||
return;
|
||||
}
|
||||
// At end of queue.
|
||||
@@ -208,6 +218,7 @@ export function skipNext(): void {
|
||||
_position = 0;
|
||||
_duration = 0;
|
||||
_state = 'loading';
|
||||
_listen++;
|
||||
} else {
|
||||
// 'off' or 'one' both pause at end on EXPLICIT skip.
|
||||
_state = 'paused';
|
||||
@@ -222,6 +233,7 @@ export function skipPrev(): void {
|
||||
_position = 0;
|
||||
_duration = 0;
|
||||
_state = 'loading';
|
||||
_listen++;
|
||||
} else {
|
||||
// Seek to 0 of the current track.
|
||||
_position = 0;
|
||||
@@ -318,6 +330,7 @@ export function reportStateFromAudio(
|
||||
_position = 0;
|
||||
_state = 'loading';
|
||||
if (_audioEl) _audioEl.currentTime = 0;
|
||||
_listen++;
|
||||
return;
|
||||
}
|
||||
if (_index + 1 < _queue.length) {
|
||||
@@ -325,6 +338,7 @@ export function reportStateFromAudio(
|
||||
_position = 0;
|
||||
_duration = 0;
|
||||
_state = 'loading';
|
||||
_listen++;
|
||||
return;
|
||||
}
|
||||
if (_repeat === 'all') {
|
||||
@@ -332,6 +346,7 @@ export function reportStateFromAudio(
|
||||
_position = 0;
|
||||
_duration = 0;
|
||||
_state = 'loading';
|
||||
_listen++;
|
||||
} else {
|
||||
_state = 'paused';
|
||||
_position = _duration;
|
||||
@@ -353,6 +368,7 @@ function handleLoadFailure(detail?: string): void {
|
||||
_duration = 0;
|
||||
_state = 'loading';
|
||||
_error = null;
|
||||
_listen++;
|
||||
return;
|
||||
}
|
||||
// Whole queue is unplayable. If it came from a refreshable source, the
|
||||
@@ -388,6 +404,7 @@ function trySelfHeal(): boolean {
|
||||
_failureStreak = 0;
|
||||
_state = 'loading';
|
||||
_error = null;
|
||||
_listen++;
|
||||
} else {
|
||||
_state = 'error';
|
||||
_error = 'Nothing playable in this mix right now.';
|
||||
@@ -546,6 +563,7 @@ export function playFromQueueIndex(idx: number): void {
|
||||
_duration = 0;
|
||||
_state = 'loading';
|
||||
_error = null;
|
||||
_listen++;
|
||||
}
|
||||
|
||||
export function toggleQueueDrawer(): void {
|
||||
|
||||
Reference in New Issue
Block a user