diff options
-rw-r--r-- | app.js | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -23,23 +23,23 @@ function onNthClip(index, action) { | |||
23 | 23 | ||
24 | document.addEventListener("keydown", event => { | 24 | document.addEventListener("keydown", event => { |
25 | if (event.key.match(/[1-9]/)) | 25 | if (event.key.match(/[1-9]/)) |
26 | onNthClip(parseInt(event.key), clip => clip.play()); | 26 | onNthClip(parseInt(event.key), clip => playFromStart(clip)); |
27 | }); | 27 | }); |
28 | 28 | ||
29 | document.addEventListener("keyup", event => { | 29 | document.addEventListener("keyup", event => { |
30 | if (event.key.match(/[1-9]/)) | 30 | if (event.key.match(/[1-9]/)) |
31 | onNthClip(parseInt(event.key), clip => stopPlayer(clip)); | 31 | onNthClip(parseInt(event.key), clip => clip.pause()); |
32 | }); | 32 | }); |
33 | 33 | ||
34 | function stopPlayer(player) { | 34 | function playFromStart(player) { |
35 | player.pause(); | 35 | if (!player.paused) return; |
36 | player.currentTime = 0; | 36 | player.currentTime = 0; |
37 | player.play(); | ||
37 | } | 38 | } |
38 | 39 | ||
39 | function stopOtherPlayersExcept(player) { | 40 | function stopOtherPlayersExcept(player) { |
40 | document.querySelectorAll("audio").forEach(other => { | 41 | document.querySelectorAll("audio").forEach(other => { |
41 | if (other != player) | 42 | if (other != player) other.pause(); |
42 | stopPlayer(other); | ||
43 | }); | 43 | }); |
44 | } | 44 | } |
45 | 45 | ||