summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorctucx <c@ctu.cx>2021-03-06 20:36:43 +0100
committerctucx <c@ctu.cx>2021-03-06 20:36:43 +0100
commit4abc74c024995fb508c0493a8fcf1207a0b78b4a (patch)
treeaad2c35c1a31309f309c140fbfedeb585a855a78
parent45dd844c9d098fbcb567f985d1eb1061e6581754 (diff)
downloadwebmusic-nginx-4abc74c024995fb508c0493a8fcf1207a0b78b4a.tar.gz
webmusic-nginx-4abc74c024995fb508c0493a8fcf1207a0b78b4a.tar.bz2
webmusic-nginx-4abc74c024995fb508c0493a8fcf1207a0b78b4a.zip
webmusic.js: code improovements
-rw-r--r--webmusic.js21
1 files changed, 13 insertions, 8 deletions
diff --git a/webmusic.js b/webmusic.js
index a113a9e..a939cb5 100644
--- a/webmusic.js
+++ b/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])
}