1
0

Added JS code for a custom player.

This commit is contained in:
Alexander Andreev 2023-08-20 01:20:28 +04:00
parent 4bdbc28f43
commit 8d372645ce
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -43,3 +43,30 @@ document.getElementById("btn-update").addEventListener("click", () => {
setInterval(updateRadioStatus, 45000);
setInterval(updateLastPlayedSong, 45000);
let audio = document.getElementsByTagName("audio")[0];
let volume = $("volume");
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();
e.target.style.maskImage = audio.paused ? "url(/assets/img/play.svg)" : "url(/assets/img/stop.svg)"; });
audio.addEventListener("timeupdate", e => {
const ct = e.target.currentTime;
const s = Math.floor(ct % 60);
const m = Math.floor((ct / 60) % 60);
const h = Math.floor(ct / 3600);
$("cur-time").textContent = `${h}h ${m}m ${s}s`; });
volume.addEventListener("input", e => {
audio.volume = parseFloat(e.target.value) / 100.0; });
$("vol-up").addEventListener("click", () => {
volume.value = +volume.value + 10; audio.volume = +volume.value / 100.0; });
$("vol-down").addEventListener("click", () => {
volume.value -= 10; audio.volume = +volume.value / 100.0; });