summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorctucx <c@ctu.cx>2021-03-06 20:32:48 +0100
committerctucx <c@ctu.cx>2021-03-06 20:32:48 +0100
commit45dd844c9d098fbcb567f985d1eb1061e6581754 (patch)
tree0acb37fa53856c3630785137fcc364e5b50c49a8
parent5b35aa858f3996740bd973eb16c4eb39e25eec7d (diff)
downloadwebmusic-nginx-45dd844c9d098fbcb567f985d1eb1061e6581754.tar.gz
webmusic-nginx-45dd844c9d098fbcb567f985d1eb1061e6581754.tar.bz2
webmusic-nginx-45dd844c9d098fbcb567f985d1eb1061e6581754.zip
webmusic.js: replace spaces with tabs
-rw-r--r--webmusic.js258
1 files changed, 129 insertions, 129 deletions
diff --git a/webmusic.js b/webmusic.js
index 2b9323d..a113a9e 100644
--- a/webmusic.js
+++ b/webmusic.js
@@ -6,174 +6,174 @@ let total = 0;
let index = 0;
let sound = new Howl({
- src: [''],
- format: "mp3",
- html5: true
+ src: [''],
+ format: "mp3",
+ html5: true
});
setInterval(function () {
- updateState();
+ updateState();
}, 1000);
window.onload = function () {
- initState();
- updateState()
+ initState();
+ updateState()
};
window.onkeyup = function (event) {
- switch (event.key) {
- case " ":
- case "p":
- if (gstate == "idle" && total !== 0) {
- playSong(queue[0])
- } else {
- togglePlayback();
- }
- break;
-
- case "r":
- toggleRepeat();
- break;
-
- case "c":
- toggleContinue();
- break;
-
- case "ArrowUp":
- previousTrack();
- break;
-
- case "ArrowDown":
- nextTrack();
- break;
-
- case "ArrowLeft":
- if (sound.seek() < 10) {
- sound.seek(0);
- } else {
- sound.seek(sound.seek()-10);
- }
- break;
-
- case "ArrowRight":
- sound.seek(sound.seek()+10);
- break;
-
- case "Escape":
- document.getElementById("back").click();
- break;
- }
+ switch (event.key) {
+ case " ":
+ case "p":
+ if (gstate == "idle" && total !== 0) {
+ playSong(queue[0])
+ } else {
+ togglePlayback();
+ }
+ break;
+
+ case "r":
+ toggleRepeat();
+ break;
+
+ case "c":
+ toggleContinue();
+ break;
+
+ case "ArrowUp":
+ previousTrack();
+ break;
+
+ case "ArrowDown":
+ nextTrack();
+ break;
+
+ case "ArrowLeft":
+ if (sound.seek() < 10) {
+ sound.seek(0);
+ } else {
+ sound.seek(sound.seek()-10);
+ }
+ break;
+
+ case "ArrowRight":
+ sound.seek(sound.seek()+10);
+ break;
+
+ case "Escape":
+ document.getElementById("back").click();
+ break;
+ }
};
function togglePlayback() {
- if (sound.playing())
- sound.pause();
- else
- sound.play();
+ if (sound.playing())
+ sound.pause();
+ else
+ sound.play();
}
function setState(state) {
- gstate = state;
- console.log("now in state: " + state);
- updateState();
+ gstate = state;
+ console.log("now in state: " + state);
+ updateState();
}
function playSong(url) {
- if (document.getElementsByClassName("playing").length > 0)
- document.getElementsByClassName("playing")[0].classList.remove("playing");
- index = queue.indexOf(url);
- sound.stop();
- sound.unload();
- sound = null;
- delete sound;
-
- sound = new Howl({
- src: [url],
- html5: true
- });
-
- setState("loading");
- sound.play();
- sound.loop(repeat);
-
- document.querySelectorAll('[onclick="playSong(\''+url+'\')"]')[0].classList.add("playing");
-
- sound.on("play", function () {
- setState("playing");
- });
- sound.on("loaderror", function () {
- setState("error loading track")
- });
- sound.on("playerror", function () {
- setState("error opening audio device")
- });
- sound.on("end", function () {
- setState("idle");
- nextTrack()
- });
- sound.on("pause", function () {
- setState("paused")
- });
+ if (document.getElementsByClassName("playing").length > 0)
+ document.getElementsByClassName("playing")[0].classList.remove("playing");
+ index = queue.indexOf(url);
+ sound.stop();
+ sound.unload();
+ sound = null;
+ delete sound;
+
+ sound = new Howl({
+ src: [url],
+ html5: true
+ });
+
+ setState("loading");
+ sound.play();
+ sound.loop(repeat);
+
+ document.querySelectorAll('[onclick="playSong(\''+url+'\')"]')[0].classList.add("playing");
+
+ sound.on("play", function () {
+ setState("playing");
+ });
+ sound.on("loaderror", function () {
+ setState("error loading track")
+ });
+ sound.on("playerror", function () {
+ setState("error opening audio device")
+ });
+ sound.on("end", function () {
+ setState("idle");
+ nextTrack()
+ });
+ sound.on("pause", function () {
+ setState("paused")
+ });
}
function toggleRepeat() {
- repeat = !repeat;
- continuelist = !repeat;
- sound.loop(repeat);
- updateState();
+ repeat = !repeat;
+ continuelist = !repeat;
+ sound.loop(repeat);
+ updateState();
}
function toggleContinue() {
- continuelist = !continuelist;
- updateState();
+ continuelist = !continuelist;
+ updateState();
}
function updateState() {
- document.getElementById("state").setAttribute('onclick', 'togglePlayback()');
- let statestr = "[";
- statestr += gstate;
- if (sound.playing())
- statestr += " " + formatTime(Math.round(sound.seek())) + "/" + formatTime(Math.round(sound.duration()));
-
- statestr += "]";
- document.getElementById("state").innerHTML = statestr;
- let flags = "[";
- if (repeat)
- flags += '<a onclick="toggleRepeat()" href="#" style="color:#6b9969">R</a>';
- else
- flags += '<a onclick="toggleRepeat()" href="#">R</a>';
- if (continuelist)
- flags += '<a onclick="toggleContinue()" href="#" style="color:#6b9969">C</a>';
- else
- flags += '<a onclick="toggleContinue()" href="#">C</a>';
-
- document.getElementById("flags").innerHTML = flags + "]";
+ document.getElementById("state").setAttribute('onclick', 'togglePlayback()');
+ let statestr = "[";
+ statestr += gstate;
+ if (sound.playing())
+ statestr += " " + formatTime(Math.round(sound.seek())) + "/" + formatTime(Math.round(sound.duration()));
+
+ statestr += "]";
+ document.getElementById("state").innerHTML = statestr;
+ let flags = "[";
+ if (repeat)
+ flags += '<a onclick="toggleRepeat()" href="#" style="color:#6b9969">R</a>';
+ else
+ flags += '<a onclick="toggleRepeat()" href="#">R</a>';
+ if (continuelist)
+ flags += '<a onclick="toggleContinue()" href="#" style="color:#6b9969">C</a>';
+ else
+ flags += '<a onclick="toggleContinue()" href="#">C</a>';
+
+ document.getElementById("flags").innerHTML = flags + "]";
}
function initState() {
- total = queue.length;
+ total = queue.length;
}
function previousTrack() {
- if (index-- === 0)
- index = total-1;
- if (continuelist) {
- playSong(queue[index])
- }
+ if (index-- === 0)
+ index = total-1;
+ if (continuelist) {
+ playSong(queue[index])
+ }
}
function nextTrack() {
- if (++index === total)
- index = 0;
- if (continuelist) {
- playSong(queue[index])
- }
+ if (++index === total)
+ index = 0;
+ if (continuelist) {
+ playSong(queue[index])
+ }
}
function formatTime(secs) {
- const minutes = Math.floor(secs / 60) || 0;
- const seconds = (secs - minutes * 60) || 0;
- return minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
+ const minutes = Math.floor(secs / 60) || 0;
+ const seconds = (secs - minutes * 60) || 0;
+ return minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
}