From 7a31359cd4186ae33ba9ff2c2856d7c470e2c680 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Sun, 8 Oct 2023 10:16:33 +0800 Subject: [PATCH] Media Overlay: add volume setting --- epub.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/epub.js b/epub.js index 322c6e1..ea69849 100644 --- a/epub.js +++ b/epub.js @@ -272,6 +272,7 @@ class MediaOverlay extends EventTarget { #audioIndex #itemIndex #audio + #volume = 1 #rate = 1 constructor(book, loadXML) { super() @@ -356,6 +357,7 @@ class MediaOverlay extends EventTarget { }) audio.addEventListener('canplaythrough', () => { audio.currentTime = this.#activeItem.begin ?? 0 + audio.volume = this.#volume audio.playbackRate = this.#rate audio.play().catch(e => this.#error(e)) }) @@ -395,6 +397,10 @@ class MediaOverlay extends EventTarget { next() { this.#play(this.#audioIndex, this.#itemIndex + 1) } + setVolume(volume) { + this.#volume = volume + if (this.#audio) this.#audio.volume = volume + } setRate(rate) { this.#rate = rate if (this.#audio) this.#audio.playbackRate = rate