summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-07 13:38:29 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-07 13:38:29 +0100
commit197584b7f9477155b278b7bfe8f4a0ad2db38d3c (patch)
tree90d66510e69e886e748878258df1b3b1cef76f37
parent2d4ff7689285e1167905bd718b69c6a9ef323368 (diff)
webmusic.js: rename variable 'sound' to 'audioPlayer'
-rw-r--r--webmusic.js44
1 files changed, 22 insertions, 22 deletions
diff --git a/webmusic.js b/webmusic.js
index 242c8a4..024a4d9 100644
--- 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 += "]";