web: prepare the next track only after the current one is playing and fully buffered

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Sonnet 5.5 committed 2026-10-20 17:42:22 -07:00
1 parent a1cf0a00b3
commit 48faa6682f
1 file changed
+15 -2
+15 -2
View File
@@ -359,11 +359,24 @@ const Q = {
E.load(srcs, posSec, play); E.load(srcs, posSec, play);
Wave.load(e); Wave.load(e);
Stems.prepare(e); Stems.prepare(e);
const nt = this.items[this.i + 1]?.t; this.prepareNext();
if (nt) Stems.prepare(Stems.find(nt));
UI.all(); save(); UI.all(); save();
}, },
// Transcode the next track only once this one is playing and fully buffered, so they don't compete.
prepareNext() {
clearInterval(this.nextTimer);
const nt = this.items[this.i + 1]?.t;
if (!nt) return;
const ready = () => E.playing && !E.buffering && E.els.length
&& E.els.every(el => el.duration > 0 && el.buffered.length && el.buffered.end(el.buffered.length - 1) >= el.duration - 0.5);
this.nextTimer = setInterval(() => {
if (!ready()) return;
clearInterval(this.nextTimer);
Stems.prepare(Stems.find(nt));
}, 1000);
},
next(auto = false) { next(auto = false) {
if (auto && S.repeat === "one") { E.seek(0); E.play(); return; } if (auto && S.repeat === "one") { E.seek(0); E.play(); return; }
if (this.i + 1 < this.items.length) { this.i++; this.start(0, true); } if (this.i + 1 < this.items.length) { this.i++; this.start(0, true); }