ctucx.git: webmusic-nginx

nginx xslt-based index files optimized for music, inspired by https://git.ztn.sh/zotan/webmusic

commit 197584b7f9477155b278b7bfe8f4a0ad2db38d3c
parent 2d4ff7689285e1167905bd718b69c6a9ef323368
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 7 Mar 2021 13:38:29 +0100

webmusic.js: rename variable 'sound' to 'audioPlayer'
1 file changed, 22 insertions(+), 22 deletions(-)
M
webmusic.js
|
44
++++++++++++++++++++++----------------------
diff --git a/webmusic.js b/webmusic.js
@@ -4,7 +4,7 @@ let continuelist = true;
 let total = 0;
 let index = 0;
 
-let sound = new Audio();
+let audioPlayer = new Audio();
 
 window.onload = function () {
 	initState();

@@ -43,15 +43,15 @@ window.onkeyup = function (event) {
 			break;
 
 		case "ArrowLeft":
-			if (sound.currentTime < 10) {
-				sound.currentTime = 0;
+			if (audioPlayer.currentTime < 10) {
+				audioPlayer.currentTime = 0;
 			} else {
-				sound.currentTime = sound.currentTime-10;
+				audioPlayer.currentTime = audioPlayer.currentTime-10;
 			}
 			break;
 
 		case "ArrowRight":
-			sound.currentTime = sound.currentTime+10;
+			audioPlayer.currentTime = audioPlayer.currentTime+10;
 			break;
 
 		case "Escape":

@@ -85,10 +85,10 @@ function initState() {
 }
 
 function togglePlayback() {
-	if (sound.paused) {
-		sound.play();
+	if (audioPlayer.paused) {
+		audioPlayer.play();
 	} else {
-		sound.pause();
+		audioPlayer.pause();
 	}
 }
 

@@ -112,38 +112,38 @@ function playSong(id) {
 
 	index = element.id;
 
-	sound.pause()
-	sound.src = element.href;
+	audioPlayer.pause()
+	audioPlayer.src = element.href;
 
 	setState("loading");
-	sound.load();
+	audioPlayer.load();
 
-	sound.loop = repeat;
+	audioPlayer.loop = repeat;
 	
 	element.classList.add("playing");
 
-	sound.addEventListener("canplay", function () {
-		sound.play();
+	audioPlayer.addEventListener("canplay", function () {
+		audioPlayer.play();
 	});
 
-	sound.addEventListener("play", function () {
+	audioPlayer.addEventListener("play", function () {
 		setState("playing");
 	});
 
-	sound.addEventListener("pause", function () {
+	audioPlayer.addEventListener("pause", function () {
 		setState("paused");
 	});
 
-	sound.addEventListener("error", function () {
+	audioPlayer.addEventListener("error", function () {
 		setState("error loading track");
 	});
 
-	sound.addEventListener("ended", function () {
+	audioPlayer.addEventListener("ended", function () {
 		setState("idle");
 		nextTrack();
 	});
 
-	sound.addEventListener("timeupdate", function () {
+	audioPlayer.addEventListener("timeupdate", function () {
 		updateState();
 	});
 }

@@ -151,7 +151,7 @@ function playSong(id) {
 function toggleRepeat() {
 	repeat = !repeat;
 	continuelist = !repeat;
-	sound.loop = repeat;
+	audioPlayer.loop = repeat;
 	updateState();
 }
 

@@ -164,8 +164,8 @@ function updateState() {
 	let statestr = "[";
 	statestr += gstate;
 
-	if (!sound.paused) {
-		statestr += " " + formatTime(Math.round(sound.currentTime)) + "/" + formatTime(Math.round(sound.duration));
+	if (!audioPlayer.paused) {
+		statestr += " " + formatTime(Math.round(audioPlayer.currentTime)) + "/" + formatTime(Math.round(audioPlayer.duration));
 	}
 
 	statestr += "]";