webmusic.js: removed debug prints, better player handling
This commit is contained in:
parent
4b6e69d4c1
commit
155e7c1bbb
16
webmusic.js
16
webmusic.js
|
@ -80,7 +80,6 @@ const initState = () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
audioPlayer.addEventListener("ended", function () {
|
audioPlayer.addEventListener("ended", function () {
|
||||||
console.log("end track: " + index);
|
|
||||||
setPlayerState("idle");
|
setPlayerState("idle");
|
||||||
nextTrack();
|
nextTrack();
|
||||||
});
|
});
|
||||||
|
@ -142,7 +141,6 @@ const updateButtonState = () => {
|
||||||
|
|
||||||
|
|
||||||
const playSong = (id) => {
|
const playSong = (id) => {
|
||||||
console.log("track id:" +id)
|
|
||||||
let element = document.getElementById(id);
|
let element = document.getElementById(id);
|
||||||
|
|
||||||
if (element === null) return;
|
if (element === null) return;
|
||||||
|
@ -155,11 +153,11 @@ const playSong = (id) => {
|
||||||
index = element.id;
|
index = element.id;
|
||||||
|
|
||||||
audioPlayer.pause()
|
audioPlayer.pause()
|
||||||
|
|
||||||
audioPlayer.src = element.href;
|
audioPlayer.src = element.href;
|
||||||
|
|
||||||
setPlayerState("loading");
|
setPlayerState("loading");
|
||||||
|
audioPlayer.load();
|
||||||
audioPlayer.loop = repeat;
|
|
||||||
|
|
||||||
element.classList.add("playing");
|
element.classList.add("playing");
|
||||||
}
|
}
|
||||||
|
@ -185,27 +183,25 @@ const toggleContinue = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const previousTrack = () => {
|
const previousTrack = () => {
|
||||||
|
if (!continuous) return;
|
||||||
if (index-- === 0) index = total-1;
|
if (index-- === 0) index = total-1;
|
||||||
|
|
||||||
if (document.getElementById(index).classList.contains('dir')) {
|
if (document.getElementById(index).classList.contains('dir')) {
|
||||||
return previousTrack();
|
return previousTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (continuous) {
|
playSong(index);
|
||||||
playSong(index)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextTrack = () => {
|
const nextTrack = () => {
|
||||||
|
if (!continuous) return;
|
||||||
if (++index === total) index = 0;
|
if (++index === total) index = 0;
|
||||||
|
|
||||||
if (document.getElementById(index).classList.contains('dir')) {
|
if (document.getElementById(index).classList.contains('dir')) {
|
||||||
return nextTrack();
|
return nextTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (continuous) {
|
playSong(index);
|
||||||
playSong(index)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatTime = (secs) => {
|
const formatTime = (secs) => {
|
||||||
|
|
Loading…
Reference in a new issue