fix: show paused state instead of error when autoplay policy blocks play()
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:
@@ -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(); }
|
||||
|
||||
Reference in New Issue
Block a user