From f58fcb9f20fa30e284fdbcf10030d7b5f7d5f707 Mon Sep 17 00:00:00 2001
From: Najam Ali Abbas <90936436+Ctoic@users.noreply.github.com>
Date: Sat, 19 Oct 2024 16:25:08 +0500
Subject: [PATCH] Implement audio speed control
Related to #108
Add speed control functionality to the audiobook player.
* Add speed control buttons (0.5x, 1x, 1.5x, 2x) near the audio player in `adventures.html`, `fs.html`, and `rdpd.html`.
* Update `app.js` to add event listeners for speed control buttons and implement functionality to change audio playback rate based on user selection.
* Update `script.js` to add event listeners for speed control buttons and implement functionality to change audio playback rate based on user selection.
---
For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Ctoic/Lisbook/issues/108?shareId=XXXX-XXXX-XXXX-XXXX).
---
adventures.html | 13 +++++++++++++
app.js | 9 +++++++++
fs.html | 13 +++++++++++++
rdpd.html | 13 +++++++++++++
script.js | 9 +++++++++
5 files changed, 57 insertions(+)
diff --git a/adventures.html b/adventures.html
index 4680396..1f459ee 100644
--- a/adventures.html
+++ b/adventures.html
@@ -487,6 +487,19 @@
>
+
+
+ 0.5x
+
+
+ 1x
+
+
+ 1.5x
+
+
+ 2x
+
diff --git a/app.js b/app.js
index 8e52319..ac165a0 100644
--- a/app.js
+++ b/app.js
@@ -77,4 +77,13 @@ document.addEventListener("DOMContentLoaded", function () {
// Event listener for "Previous" button
if (prevBtn) prevBtn.addEventListener("click", prevPage);
+
+ // Speed control buttons functionality
+ const speedButtons = document.querySelectorAll("[id^='speed-']");
+ speedButtons.forEach((button) => {
+ button.addEventListener("click", function () {
+ const speed = parseFloat(this.id.split("-")[1]);
+ audioPlayer.playbackRate = speed;
+ });
+ });
});
diff --git a/fs.html b/fs.html
index 720e747..f368a94 100644
--- a/fs.html
+++ b/fs.html
@@ -642,6 +642,19 @@ By Mary Shelby
>
+
+
+ 0.5x
+
+
+ 1x
+
+
+ 1.5x
+
+
+ 2x
+
diff --git a/rdpd.html b/rdpd.html
index 7b46d61..d031db9 100644
--- a/rdpd.html
+++ b/rdpd.html
@@ -483,6 +483,19 @@ By Yuval Noah Harari
>
+
+
+ 0.5x
+
+
+ 1x
+
+
+ 1.5x
+
+
+ 2x
+
diff --git a/script.js b/script.js
index a7066fb..c16224a 100644
--- a/script.js
+++ b/script.js
@@ -427,6 +427,15 @@ document.addEventListener("DOMContentLoaded", function () {
}
});
});
+
+ // Speed control buttons functionality
+ const speedButtons = document.querySelectorAll("[id^='speed-']");
+ speedButtons.forEach((button) => {
+ button.addEventListener("click", function () {
+ const speed = parseFloat(this.id.split("-")[1]);
+ audioPlayer.playbackRate = speed;
+ });
+ });
});
// Function to load an HTML file into an element
function loadHTML(file, elementId) {