Skip to content

Commit

Permalink
Media Overlay: don't seek in canplaythrough
Browse files Browse the repository at this point in the history
So this is what was causing the `canplaythrough` loop in Chromium and
Firefox.
  • Loading branch information
johnfactotum committed Sep 26, 2024
1 parent 22189f1 commit 357c129
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 357c129

Please sign in to comment.