const ApiLocation = "/api" let isInfoShown = true; function GetSongs() { fetch(`${ApiLocation}/getSongs`).then(r => r.json().then(body => { console.log(body); })); } function SetRandomSong() { fetch(`${ApiLocation}/randomSong`).then(r => r.json().then(body => { const player = document.getElementById("mainAudio"); console.log(player); console.log(body); document.getElementById("Status").innerHTML = "Loading"; player.src = `${ApiLocation}/getSong?name=${encodeURI(body.Name)}`; document.getElementById("Artist").innerHTML = "Artist: " + body.Meta.Author; document.getElementById("Title").innerHTML = "Title: " + body.Meta.Name; document.getElementById("Album").innerHTML = "Album: " + body.Meta.Album; document.getElementById("Start").innerHTML = "Start: " + body.Start + "s"; player.play(); player.currentTime = body.Start document.getElementById("Status").innerHTML = "Playing"; })); } function Pause() { const player = document.getElementById("mainAudio"); player.pause(); document.getElementById("Status").innerHTML = "Paused"; } function Resume() { const player = document.getElementById("mainAudio"); player.play(); document.getElementById("Status").innerHTML = "Playing"; } function ToggleInfo() { if (isInfoShown) { document.getElementById("InfoBlock").style.display = 'none'; document.getElementById("ToggleBtn").innerHTML = 'Show info'; isInfoShown = false; } else { document.getElementById("InfoBlock").style.display = 'block'; document.getElementById("ToggleBtn").innerHTML = 'Hide info'; isInfoShown = true; } } function SetVolume() { const player = document.getElementById("mainAudio"); const slider = document.getElementById("volumeRange"); player.volume = slider.value / 100; }