]> littlesong.place Git - littlesongplace.git/commitdiff
10s skip in audio player with arrow keys
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 16 Feb 2025 15:39:44 +0000 (10:39 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 16 Feb 2025 15:39:44 +0000 (10:39 -0500)
static/player.js
todo.txt

index 868e8dd0d8942a3b7aa5278f1c0fac122a1fc3df..0dc50b6b92157ee21ddb85e5d3eb8f839946b521 100644 (file)
@@ -172,6 +172,29 @@ document.addEventListener("DOMContentLoaded", (event) => {
         audio.currentTime = audio.duration * event.target.value;
     }
 
+    // Use arrow keys for song position
+    document.addEventListener("keydown", (event) => {
+        if (["TEXTAREA", "INPUT"].includes(event.originalTarget.tagName)) {
+            return;  // Only handle key presses if no other element is selected
+        }
+        var newTime = audio.currentTime;
+        switch (event.key) {
+            case "ArrowLeft":
+                newTime -= 10;
+                break;
+            case "ArrowRight":
+                newTime += 10;
+                break;
+        }
+        if (newTime < 0) {
+            newTime = 0;
+        }
+        else if (newTime > audio.duration) {
+            newTime = audio.duration;
+        }
+        audio.currentTime = newTime;
+    });
+
     // Volume
     document.getElementById("volume-slider").oninput = function(event) {
         audio.volume = event.target.value;
index cfcd4a346eeb375b41405fb402ba160ccf4b1537..40a601edb1e0644f58d9f62c9a4cecceb59d84b6 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -2,7 +2,7 @@ NOW
 - Test playlist API
 
 SOON
-- 10s skip forwards/backwards with left/right arrow keys
+- Break up main.py
 - AJAX pages so songs can play during navigation
 - Pinned profile playlists