summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Shangreaux <shshoshin@protonmail.com>2020-01-06 14:34:43 -0600
committerGrant Shangreaux <shshoshin@protonmail.com>2020-01-06 14:56:50 -0600
commit13175b907de620e372caae126f29bcabfbd329ce (patch)
tree5ac9afb7a98759fc70a6ea1162b325b3533f7589
parentf54dc303b751722b7c9616141de102a6cb6c4d1d (diff)
Fix: trigger of playback with button sound
-rw-r--r--tape-deck.js19
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;
}