diff options
-rw-r--r-- | tape-deck.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/tape-deck.js b/tape-deck.js index 7485c92..631de23 100644 --- a/tape-deck.js +++ b/tape-deck.js @@ -5,7 +5,13 @@ const tape = new Audio(`audio/2019-mix-side-${currentSide}.mp3`); const pressPlaySound = new Audio("audio/tape-start.mp3"); const buttonPressSound = new Audio("audio/button-press.mp3"); pressPlaySound.onended = (event) => { tape.play(); }; -buttonPressSound.onended = (event) => { tape.play(); }; +buttonPressSound.onended = (event) => { + if (isPlaying()) { + playing = false; + } else { + tape.play(); + } +}; const stopImage = "images/cool-deck.png"; const playImage = "images/cool-deck.gif"; @@ -19,7 +25,11 @@ let notes = document.getElementById("notes"); let trackData = []; let currentTrackIndex = 0; let hasStarted = false; -let isPlaying = false; +let playing = false; + +function isPlaying() { + return playing; +} function loadTrackData() { fetch(`side${currentSide}.json`) @@ -30,11 +40,10 @@ function loadTrackData() { } function play() { - if (isPlaying) { + if (isPlaying()) { playButton.src = playButtonUp; buttonPressSound.play(); tape.pause(); - isPlaying = false; deck.src = stopImage; return; } @@ -46,7 +55,7 @@ function play() { buttonPressSound.play(); } - isPlaying = true; + playing = true; playButton.src = playButtonDown; deck.src = playImage; } |