From 3566e90b1a6567c06122cddf94dbfa6b33bbdb71 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 20 Aug 2023 02:10:29 +0400 Subject: [PATCH] Correct audio stopping. --- web/assets/js/main.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/assets/js/main.js b/web/assets/js/main.js index dbef807..67b46cf 100644 --- a/web/assets/js/main.js +++ b/web/assets/js/main.js @@ -47,13 +47,20 @@ setInterval(updateLastPlayedSong, 45000); let audio = document.getElementsByTagName("audio")[0]; let volume = $("volume"); +const audio_src = audio.childNodes[0].src; audio.hidden = true; audio.volume = parseFloat(volume.value) / 100.0; document.querySelector("div.player").style.display = "flex"; $("radio").style.display = "flex"; $("play").addEventListener("click", e => { - audio.paused && audio.play() || audio.pause(); + if (audio.paused) { + audio.src = audio_src; + audio.play(); + } else { + audio.pause(); + audio.src = ""; + } e.target.style.maskImage = audio.paused ? "url(/assets/img/play.svg)" : "url(/assets/img/stop.svg)"; }); audio.addEventListener("timeupdate", e => {