From: Chris Fulljames Date: Sun, 16 Feb 2025 15:39:44 +0000 (-0500) Subject: 10s skip in audio player with arrow keys X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=065cc1a35464461f9dabf329010ff54aeddb5a58;p=littlesongplace.git 10s skip in audio player with arrow keys --- diff --git a/static/player.js b/static/player.js index 868e8dd..0dc50b6 100644 --- a/static/player.js +++ b/static/player.js @@ -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; diff --git a/todo.txt b/todo.txt index cfcd4a3..40a601e 100644 --- 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