From 04c9838ab593306c84918850a608aceafb01999c Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 5 Jan 2024 02:39:01 +0100 Subject: reset position only when playing --- app.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 79ea6e8..7b5f4b0 100644 --- a/app.js +++ b/app.js @@ -23,23 +23,23 @@ function onNthClip(index, action) { document.addEventListener("keydown", event => { if (event.key.match(/[1-9]/)) - onNthClip(parseInt(event.key), clip => clip.play()); + onNthClip(parseInt(event.key), clip => playFromStart(clip)); }); document.addEventListener("keyup", event => { if (event.key.match(/[1-9]/)) - onNthClip(parseInt(event.key), clip => stopPlayer(clip)); + onNthClip(parseInt(event.key), clip => clip.pause()); }); -function stopPlayer(player) { - player.pause(); +function playFromStart(player) { + if (!player.paused) return; player.currentTime = 0; + player.play(); } function stopOtherPlayersExcept(player) { document.querySelectorAll("audio").forEach(other => { - if (other != player) - stopPlayer(other); + if (other != player) other.pause(); }); } -- cgit v1.2.3