summaryrefslogtreecommitdiff
path: root/tape-deck.js
diff options
context:
space:
mode:
Diffstat (limited to 'tape-deck.js')
-rw-r--r--tape-deck.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/tape-deck.js b/tape-deck.js
new file mode 100644
index 0000000..7d75abc
--- /dev/null
+++ b/tape-deck.js
@@ -0,0 +1,45 @@
+const urlParams = new URLSearchParams(window.location.search);
+const currentSide = urlParams.get("side");
+const sfx = new Audio("audio/tape-start.mp3");
+const tape = new Audio(`audio/2019-mix-side-${currentSide}.mp3`);
+let display = document.getElementById("notes");
+let currentTrackIndex = 0;
+
+fetch(`side${currentSide}.json`)
+ .then(response => response.json())
+ .then((trackData) => {
+ const startTimes = trackData.map( t => t.start );
+
+ sfx.play();
+
+ sfx.onended = (event) => {
+ tape.controls = true;
+ tape.play();
+ }
+
+ function isLastTrack() {
+ return currentTrackIndex + 1 === startTimes.length;
+ }
+
+ function getTrack(time) {
+ const nextIndex = currentTrackIndex + 1
+
+ if (isLastTrack()) {
+ return trackData[trackData.length - 1];
+ } else {
+ if (time >= startTimes[nextIndex]) {
+ currentTrackIndex = nextIndex;
+ }
+
+ return trackData[currentTrackIndex];
+ }
+ }
+
+
+ tape.addEventListener("timeupdate", (event) => {
+ const time = tape.currentTime;
+ const currentTrack = getTrack(time, trackData);
+ display.textContent = currentTrack.title;
+ });
+ });
+