Stop the last song from restarting and freezing service-mode lyrics

This commit is contained in:
Jonathan Sykes
2026-10-07 02:12:07 +08:00
parent 128f8e95e3
commit 2b286ae146
3 changed files with 11 additions and 1 deletions

View File

@@ -8207,6 +8207,9 @@ function onTrackEnded() {
if (!playFullMode && data.settings.loopOne) { Player.seek(0); Player.play(); return; }
if (!advanceQueue()) {
if (playFullMode) { playFullMode = false; toast('Finished playing in full'); }
// Nothing left: drop the intent to play, or the watchdog "resumes" the ended
// <audio> from 0 and the last song repeats while the lyrics stay frozen.
Player.pause();
updatePlayBtn();
$('upnext').classList.add('hidden');
}

View File

@@ -18,7 +18,8 @@
pending.set(element, request); return request;
}
function resume(element, clock) {
if (!element || !element.paused || pending.has(element)) return;
// An ended element is finished, not interrupted: play() would restart it from 0.
if (!element || !element.paused || element.ended || pending.has(element)) return;
if (clock && element !== clock && needsAlignment(element.currentTime, clock.currentTime)) element.currentTime = clock.currentTime;
return play(element);
}

View File

@@ -41,3 +41,9 @@ test('a new play after pause/source reset is not blocked by a stale promise', as
assert.equal(controller.play(audio), fresh); // old completion cannot discard the new request
finishes[1](); await fresh;
});
test('an ended element is never resumed (last song must not restart from 0)', () => {
let calls = 0;
const audio = { paused: true, ended: true, currentTime: 200, play() { calls++; return Promise.resolve(); } };
create().resume(audio, { currentTime: 200 });
assert.equal(calls, 0);
});