summaryrefslogtreecommitdiff
path: root/static/index.js
blob: 0c983a0d6d75c8341dbd765695633821f811a69e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}