diff options
author | Grant Shangreaux <shshoshin@protonmail.com> | 2020-01-06 09:56:36 -0600 |
---|---|---|
committer | Grant Shangreaux <shshoshin@protonmail.com> | 2020-01-06 09:56:36 -0600 |
commit | 227113de0e779f2919f7478181faf66551ef7c94 (patch) | |
tree | 74e8e8ff39c3be7a349e050a766f8bba6a809097 /tape-deck.js | |
parent | 4556713ef0f4500974a20e649aeeb0630e6a55b2 (diff) |
Add: hardware image play/pause button
Diffstat (limited to 'tape-deck.js')
-rw-r--r-- | tape-deck.js | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tape-deck.js b/tape-deck.js index 04b6d2d..3d10fe8 100644 --- a/tape-deck.js +++ b/tape-deck.js @@ -8,11 +8,16 @@ pressPlaySound.onended = (event) => { tape.play(); }; const stopImage = "images/cool-deck.png"; const playImage = "images/cool-deck.gif"; +let playButton = document.getElementById("play-button"); +const playButtonUp = "images/play-button-up.png"; +const playButtonDown = "images/play-button-down.png"; + let deck = document.getElementById("tape-deck"); let notes = document.getElementById("notes"); let trackData = []; let currentTrackIndex = 0; let hasStarted = false; +let isPlaying = false; function loadTrackData() { fetch(`side${currentSide}.json`) @@ -23,18 +28,24 @@ function loadTrackData() { } function play() { + if (isPlaying) { + playButton.src = playButtonUp; + tape.pause(); + isPlaying = false; + deck.src = stopImage; + return; + } + if (!hasStarted) { pressPlaySound.play(); hasStarted = true; } else { tape.play(); } - deck.src = playImage; -} -function pause() { - tape.pause(); - deck.src = stopImage; + isPlaying = true; + playButton.src = playButtonDown; + deck.src = playImage; } function isLastTrack(current, tracks) { |