From 357c129b5dbd14dbdd3b19b272084fb694a3cfa1 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Thu, 26 Sep 2024 12:53:06 +0800 Subject: [PATCH] Media Overlay: don't seek in `canplaythrough` So this is what was causing the `canplaythrough` loop in Chromium and Firefox. --- epub.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/epub.js b/epub.js index cc6a6c3..86e8f2e 100644 --- a/epub.js +++ b/epub.js @@ -456,6 +456,9 @@ class MediaOverlay extends EventTarget { const url = URL.createObjectURL(await this.book.loadBlob(src)) const audio = new Audio(url) this.#audio = audio + audio.currentTime = this.#activeItem.begin ?? 0 + audio.volume = this.#volume + audio.playbackRate = this.#rate audio.addEventListener('timeupdate', () => { if (audio.paused) return const t = audio.currentTime @@ -481,12 +484,8 @@ class MediaOverlay extends EventTarget { this.#audio = null this.#play(audioIndex + 1, 0).catch(e => this.#error(e)) }) - audio.addEventListener('canplaythrough', () => { - audio.currentTime = this.#activeItem.begin ?? 0 - audio.volume = this.#volume - audio.playbackRate = this.#rate - audio.play().catch(e => this.#error(e)) - }, { once: true }) + audio.addEventListener('canplaythrough', () => + audio.play().catch(e => this.#error(e)), { once: true }) } async start(sectionIndex, filter = () => true) { this.#audio?.pause()