fix: always autoplay after generation and resume TTS on HTMX chapter swap
This commit is contained in:
@@ -2927,7 +2927,12 @@ const chapterTmpl = `
|
|||||||
highlightPara(0);
|
highlightPara(0);
|
||||||
generateAudio(CHAPTER_N, function (url) {
|
generateAudio(CHAPTER_N, function (url) {
|
||||||
if (stale()) return;
|
if (stale()) return;
|
||||||
if (autoplay) audio.autoplay = true;
|
// Always set autoplay=true before load(): the browser needs this hint set
|
||||||
|
// synchronously before load() regardless of whether we got here via a user
|
||||||
|
// gesture or a programmatic trigger (e.g. chapter transition). The canplay
|
||||||
|
// handler will call play() as well, but autoplay on the element is the only
|
||||||
|
// reliable path after an async fetch where the gesture stack is gone.
|
||||||
|
audio.autoplay = true;
|
||||||
audio.src = url; audio.load();
|
audio.src = url; audio.load();
|
||||||
audio.playbackRate = getSpeed();
|
audio.playbackRate = getSpeed();
|
||||||
registerMediaSession();
|
registerMediaSession();
|
||||||
@@ -2943,7 +2948,15 @@ const chapterTmpl = `
|
|||||||
startAudio();
|
startAudio();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.__ttsBeforeSwap = function () { window.__ttsGen++; stop(); };
|
window.__ttsBeforeSwap = function () {
|
||||||
|
// If TTS is active (generating or has audio loaded), persist the autostart
|
||||||
|
// flag so the incoming chapter's init code will restart TTS automatically.
|
||||||
|
var wasActive = currentAudioCtrl !== null || (audio.src && !audio.ended);
|
||||||
|
if (wasActive) {
|
||||||
|
try { localStorage.setItem('tts_autostart', '1'); } catch(_) {}
|
||||||
|
}
|
||||||
|
window.__ttsGen++; stop();
|
||||||
|
};
|
||||||
document.body.addEventListener('htmx:beforeSwap', window.__ttsBeforeSwap);
|
document.body.addEventListener('htmx:beforeSwap', window.__ttsBeforeSwap);
|
||||||
|
|
||||||
var _autostart = false;
|
var _autostart = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user