webmusic.js: rename variable 'sound' to 'audioPlayer'
This commit is contained in:
parent
599b1ef413
commit
6a9dd5b051
44
webmusic.js
44
webmusic.js
|
@ -4,7 +4,7 @@ let continuelist = true;
|
||||||
let total = 0;
|
let total = 0;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
||||||
let sound = new Audio();
|
let audioPlayer = new Audio();
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
initState();
|
initState();
|
||||||
|
@ -43,15 +43,15 @@ window.onkeyup = function (event) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ArrowLeft":
|
case "ArrowLeft":
|
||||||
if (sound.currentTime < 10) {
|
if (audioPlayer.currentTime < 10) {
|
||||||
sound.currentTime = 0;
|
audioPlayer.currentTime = 0;
|
||||||
} else {
|
} else {
|
||||||
sound.currentTime = sound.currentTime-10;
|
audioPlayer.currentTime = audioPlayer.currentTime-10;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ArrowRight":
|
case "ArrowRight":
|
||||||
sound.currentTime = sound.currentTime+10;
|
audioPlayer.currentTime = audioPlayer.currentTime+10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Escape":
|
case "Escape":
|
||||||
|
@ -85,10 +85,10 @@ function initState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function togglePlayback() {
|
function togglePlayback() {
|
||||||
if (sound.paused) {
|
if (audioPlayer.paused) {
|
||||||
sound.play();
|
audioPlayer.play();
|
||||||
} else {
|
} else {
|
||||||
sound.pause();
|
audioPlayer.pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,38 +112,38 @@ function playSong(id) {
|
||||||
|
|
||||||
index = element.id;
|
index = element.id;
|
||||||
|
|
||||||
sound.pause()
|
audioPlayer.pause()
|
||||||
sound.src = element.href;
|
audioPlayer.src = element.href;
|
||||||
|
|
||||||
setState("loading");
|
setState("loading");
|
||||||
sound.load();
|
audioPlayer.load();
|
||||||
|
|
||||||
sound.loop = repeat;
|
audioPlayer.loop = repeat;
|
||||||
|
|
||||||
element.classList.add("playing");
|
element.classList.add("playing");
|
||||||
|
|
||||||
sound.addEventListener("canplay", function () {
|
audioPlayer.addEventListener("canplay", function () {
|
||||||
sound.play();
|
audioPlayer.play();
|
||||||
});
|
});
|
||||||
|
|
||||||
sound.addEventListener("play", function () {
|
audioPlayer.addEventListener("play", function () {
|
||||||
setState("playing");
|
setState("playing");
|
||||||
});
|
});
|
||||||
|
|
||||||
sound.addEventListener("pause", function () {
|
audioPlayer.addEventListener("pause", function () {
|
||||||
setState("paused");
|
setState("paused");
|
||||||
});
|
});
|
||||||
|
|
||||||
sound.addEventListener("error", function () {
|
audioPlayer.addEventListener("error", function () {
|
||||||
setState("error loading track");
|
setState("error loading track");
|
||||||
});
|
});
|
||||||
|
|
||||||
sound.addEventListener("ended", function () {
|
audioPlayer.addEventListener("ended", function () {
|
||||||
setState("idle");
|
setState("idle");
|
||||||
nextTrack();
|
nextTrack();
|
||||||
});
|
});
|
||||||
|
|
||||||
sound.addEventListener("timeupdate", function () {
|
audioPlayer.addEventListener("timeupdate", function () {
|
||||||
updateState();
|
updateState();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ function playSong(id) {
|
||||||
function toggleRepeat() {
|
function toggleRepeat() {
|
||||||
repeat = !repeat;
|
repeat = !repeat;
|
||||||
continuelist = !repeat;
|
continuelist = !repeat;
|
||||||
sound.loop = repeat;
|
audioPlayer.loop = repeat;
|
||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +164,8 @@ function updateState() {
|
||||||
let statestr = "[";
|
let statestr = "[";
|
||||||
statestr += gstate;
|
statestr += gstate;
|
||||||
|
|
||||||
if (!sound.paused) {
|
if (!audioPlayer.paused) {
|
||||||
statestr += " " + formatTime(Math.round(sound.currentTime)) + "/" + formatTime(Math.round(sound.duration));
|
statestr += " " + formatTime(Math.round(audioPlayer.currentTime)) + "/" + formatTime(Math.round(audioPlayer.duration));
|
||||||
}
|
}
|
||||||
|
|
||||||
statestr += "]";
|
statestr += "]";
|
||||||
|
|
Loading…
Reference in a new issue