webmusic.js: code improovements
This commit is contained in:
parent
81b67db9a1
commit
822996211f
21
webmusic.js
21
webmusic.js
|
@ -67,22 +67,26 @@ window.onkeyup = function (event) {
|
|||
|
||||
|
||||
function togglePlayback() {
|
||||
if (sound.playing())
|
||||
if (sound.playing()) {
|
||||
sound.pause();
|
||||
else
|
||||
} else {
|
||||
sound.play();
|
||||
}
|
||||
}
|
||||
|
||||
function setState(state) {
|
||||
gstate = state;
|
||||
|
||||
console.log("now in state: " + state);
|
||||
updateState();
|
||||
}
|
||||
|
||||
|
||||
function playSong(url) {
|
||||
if (document.getElementsByClassName("playing").length > 0)
|
||||
if (document.getElementsByClassName("playing").length > 0) {
|
||||
document.getElementsByClassName("playing")[0].classList.remove("playing");
|
||||
}
|
||||
|
||||
index = queue.indexOf(url);
|
||||
sound.stop();
|
||||
sound.unload();
|
||||
|
@ -134,8 +138,9 @@ function updateState() {
|
|||
document.getElementById("state").setAttribute('onclick', 'togglePlayback()');
|
||||
let statestr = "[";
|
||||
statestr += gstate;
|
||||
if (sound.playing())
|
||||
if (sound.playing()) {
|
||||
statestr += " " + formatTime(Math.round(sound.seek())) + "/" + formatTime(Math.round(sound.duration()));
|
||||
}
|
||||
|
||||
statestr += "]";
|
||||
document.getElementById("state").innerHTML = statestr;
|
||||
|
@ -157,16 +162,16 @@ function initState() {
|
|||
}
|
||||
|
||||
function previousTrack() {
|
||||
if (index-- === 0)
|
||||
index = total-1;
|
||||
if (index-- === 0) index = total-1;
|
||||
|
||||
if (continuelist) {
|
||||
playSong(queue[index])
|
||||
}
|
||||
}
|
||||
|
||||
function nextTrack() {
|
||||
if (++index === total)
|
||||
index = 0;
|
||||
if (++index === total) index = 0;
|
||||
|
||||
if (continuelist) {
|
||||
playSong(queue[index])
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue