fix: switch audio to preload=auto when player opens or seek is triggered

preload='metadata' only fetches the header; every seek then requires a
fresh Range request and buffering delay. Switching to 'auto' lets the
browser start buffering the file immediately so seeking into it is fast.
Set both in togglePlayer (on open) and in seekToSection/jumpToDaySection
(in case the player was already open with the old metadata-only mode).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-02 23:24:17 +02:00
parent a68af56421
commit b6b328dfb8
+3 -1
View File
@@ -861,7 +861,7 @@ function togglePlayer(idx, filename) {
if (!open) { if (!open) {
if (!audio.getAttribute('data-src-set')) { if (!audio.getAttribute('data-src-set')) {
audio.preload = 'metadata'; audio.preload = 'auto';
audio.src = '/stream/' + encodeURIComponent(filename); audio.src = '/stream/' + encodeURIComponent(filename);
audio.load(); audio.load();
audio.setAttribute('data-src-set','1'); audio.setAttribute('data-src-set','1');
@@ -931,6 +931,7 @@ function seekToSection(idx, filename, startSec, endSec, sectionIdx) {
if (pbtn.getAttribute('aria-expanded') !== 'true') togglePlayer(idx, filename); if (pbtn.getAttribute('aria-expanded') !== 'true') togglePlayer(idx, filename);
activePlayerIdx = idx; activePlayerIdx = idx;
const audio = document.getElementById('aud-'+idx); const audio = document.getElementById('aud-'+idx);
audio.preload = 'auto';
const seekTo = Math.max(0, startSec - getPreroll()); const seekTo = Math.max(0, startSec - getPreroll());
const doSeek = () => { audio.currentTime = seekTo; audio.play().catch(() => {}); }; const doSeek = () => { audio.currentTime = seekTo; audio.play().catch(() => {}); };
if (audio.readyState >= 1) doSeek(); if (audio.readyState >= 1) doSeek();
@@ -1540,6 +1541,7 @@ function jumpToDaySection(si) {
const audio = document.getElementById('aud-' + fileIdx); const audio = document.getElementById('aud-' + fileIdx);
if (!audio) return; if (!audio) return;
audio.preload = 'auto';
const seekTo = Math.max(0, start - getPreroll()); const seekTo = Math.max(0, start - getPreroll());
const doSeek = () => { audio.currentTime = seekTo; audio.play().catch(() => {}); }; const doSeek = () => { audio.currentTime = seekTo; audio.play().catch(() => {}); };
if (audio.readyState >= 1) doSeek(); if (audio.readyState >= 1) doSeek();