fix: show paused state instead of error when autoplay policy blocks play()
Some checks failed
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

When the browser blocks audio.play() with NotAllowedError (no user gesture),
the player was surfacing an error badge and the user had no hint it was ready.
Now onCanPlay catches NotAllowedError specifically and calls setPaused() so
the audio element keeps its src and the user just needs to tap play once.
This commit is contained in:
Admin
2026-03-02 19:18:28 +05:00
parent 1c547519e8
commit 9388a355e5

View File

@@ -2872,7 +2872,7 @@ const chapterTmpl = `
if (!activePara || activePara !== paras[idx]) highlightPara(idx);
}
function onCanPlay() { if (stale()) { audio.removeEventListener('canplay', onCanPlay); return; } audio.autoplay = false; if (audio.paused) audio.play().then(setPlaying).catch(function(e){ setError(e.message); }); }
function onCanPlay() { if (stale()) { audio.removeEventListener('canplay', onCanPlay); return; } audio.autoplay = false; if (audio.paused) audio.play().then(setPlaying).catch(function(e){ if (e.name === 'NotAllowedError') setPaused(); else setError(e.message); }); }
function onWaiting() { if (!stale()) setStatus('Buffering\u2026'); }
function onPlaying() { if (!stale()) setPlaying(); }
function onPause() { if (!stale() && !audio.ended) setPaused(); }