Revert "polish(web): warm next track via fetch to shrink media-tile gap"

This reverts commit 6131eea9ec.
This commit is contained in:
Honey committed 2026-06-26 21:00:44 +02:00
1 parent 6131eea9ec
commit e1ec1f3660
1 file changed
+8 -18
+8 -18
View File
@@ -276,13 +276,10 @@ function _setAudioSession() {
try { if(navigator.audioSession) navigator.audioSession.type = 'playback'; } catch {}
}
// ─── PRELOAD — warm the next track via fetch (NO second <audio> element) ─────
// A second media element makes Chromium flip the OS media session on skip (tile flicker).
// So we prefetch the next track's first chunk with fetch() to warm the HTTP cache + TLS
// connection — the main element's src-swap then starts faster → smaller gap → less tile flash.
// ─── PRELOAD — shadow Audio element actually buffers the next track ──────────
let _preUrl = '';
let _preId = '';
let _preAbort = null;
let _preAudio = null;
function _nextIdx() {
if(S.repeat === 'one') return S.qIdx;
@@ -296,17 +293,11 @@ function _preloadNext() {
const ni = _nextIdx();
if(ni < 0) return;
const next = S.queue[ni];
if(!next || _preId === next.id) return;
_preId = next.id;
_preUrl = streamUrl(next.id);
// Warm the cache/connection with the first few MB (enough to start playback instantly).
try {
_preAbort?.abort();
_preAbort = new AbortController();
fetch(_preUrl, { signal: _preAbort.signal, headers: { Range: 'bytes=0-4194303' } })
.then(r => r.arrayBuffer()) // drain so the bytes land in the HTTP cache
.catch(() => {});
} catch {}
if(!next) return;
// (b) EXPERIMENT — no separate preload <audio> element. Navidrome's player keeps a single
// element only; a second buffering media element appears to make Chromium flip the OS media
// session on skip (Windows tile flicker). We rely on the main element's preload="auto" + the
// browser HTTP cache instead, and just warm the next cover art. Easy to revert if it doesn't help.
if(next.coverArt) {
[256, 512, 1024].forEach(size => {
const img = new Image();
@@ -317,8 +308,7 @@ function _preloadNext() {
function _clearPreload() {
_preId = ''; _preUrl = '';
try { _preAbort?.abort(); } catch {}
_preAbort = null;
if(_preAudio) { _preAudio.src = ''; _preAudio = null; }
}
// ─── PLAY HISTORY (for prev-in-shuffle) ──────────────────────────────────────