Media Overlay: don't seek in canplaythrough

So this is what was causing the `canplaythrough` loop in Chromium and
Firefox.
This commit is contained in:
John Factotum
2024-09-26 12:56:09 +08:00
parent 22189f184e
commit 357c129b5d
+5 -6
View File
@@ -456,6 +456,9 @@ class MediaOverlay extends EventTarget {
const url = URL.createObjectURL(await this.book.loadBlob(src)) const url = URL.createObjectURL(await this.book.loadBlob(src))
const audio = new Audio(url) const audio = new Audio(url)
this.#audio = audio this.#audio = audio
audio.currentTime = this.#activeItem.begin ?? 0
audio.volume = this.#volume
audio.playbackRate = this.#rate
audio.addEventListener('timeupdate', () => { audio.addEventListener('timeupdate', () => {
if (audio.paused) return if (audio.paused) return
const t = audio.currentTime const t = audio.currentTime
@@ -481,12 +484,8 @@ class MediaOverlay extends EventTarget {
this.#audio = null this.#audio = null
this.#play(audioIndex + 1, 0).catch(e => this.#error(e)) this.#play(audioIndex + 1, 0).catch(e => this.#error(e))
}) })
audio.addEventListener('canplaythrough', () => { audio.addEventListener('canplaythrough', () =>
audio.currentTime = this.#activeItem.begin ?? 0 audio.play().catch(e => this.#error(e)), { once: true })
audio.volume = this.#volume
audio.playbackRate = this.#rate
audio.play().catch(e => this.#error(e))
}, { once: true })
} }
async start(sectionIndex, filter = () => true) { async start(sectionIndex, filter = () => true) {
this.#audio?.pause() this.#audio?.pause()