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 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 += "]";
|
||||
|
|
Loading…
Reference in a new issue