Revert "polish(web): warm next track via fetch to shrink media-tile gap"
This reverts commit 6131eea9ec.
This commit is contained in:
1 parent
6131eea9ec
commit
e1ec1f3660
1 file changed
+8
-18
+8
-18
@@ -276,13 +276,10 @@ function _setAudioSession() {
|
|||||||
try { if(navigator.audioSession) navigator.audioSession.type = 'playback'; } catch {}
|
try { if(navigator.audioSession) navigator.audioSession.type = 'playback'; } catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── PRELOAD — warm the next track via fetch (NO second <audio> element) ─────
|
// ─── PRELOAD — shadow Audio element actually buffers the next track ──────────
|
||||||
// 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.
|
|
||||||
let _preUrl = '';
|
let _preUrl = '';
|
||||||
let _preId = '';
|
let _preId = '';
|
||||||
let _preAbort = null;
|
let _preAudio = null;
|
||||||
|
|
||||||
function _nextIdx() {
|
function _nextIdx() {
|
||||||
if(S.repeat === 'one') return S.qIdx;
|
if(S.repeat === 'one') return S.qIdx;
|
||||||
@@ -296,17 +293,11 @@ function _preloadNext() {
|
|||||||
const ni = _nextIdx();
|
const ni = _nextIdx();
|
||||||
if(ni < 0) return;
|
if(ni < 0) return;
|
||||||
const next = S.queue[ni];
|
const next = S.queue[ni];
|
||||||
if(!next || _preId === next.id) return;
|
if(!next) return;
|
||||||
_preId = next.id;
|
// (b) EXPERIMENT — no separate preload <audio> element. Navidrome's player keeps a single
|
||||||
_preUrl = streamUrl(next.id);
|
// element only; a second buffering media element appears to make Chromium flip the OS media
|
||||||
// Warm the cache/connection with the first few MB (enough to start playback instantly).
|
// session on skip (Windows tile flicker). We rely on the main element's preload="auto" + the
|
||||||
try {
|
// browser HTTP cache instead, and just warm the next cover art. Easy to revert if it doesn't help.
|
||||||
_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.coverArt) {
|
if(next.coverArt) {
|
||||||
[256, 512, 1024].forEach(size => {
|
[256, 512, 1024].forEach(size => {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
@@ -317,8 +308,7 @@ function _preloadNext() {
|
|||||||
|
|
||||||
function _clearPreload() {
|
function _clearPreload() {
|
||||||
_preId = ''; _preUrl = '';
|
_preId = ''; _preUrl = '';
|
||||||
try { _preAbort?.abort(); } catch {}
|
if(_preAudio) { _preAudio.src = ''; _preAudio = null; }
|
||||||
_preAbort = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── PLAY HISTORY (for prev-in-shuffle) ──────────────────────────────────────
|
// ─── PLAY HISTORY (for prev-in-shuffle) ──────────────────────────────────────
|
||||||
|
|||||||
Reference in new issue
Block a user