summaryrefslogtreecommitdiff
path: root/static/index.js
blob: 237386c65b727463914dba5780ed0350e0a79ed8 (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
let isInfoShown = true;

function GetSongs() {
    fetch("/api/getSongs").then(r => r.json().then(body => {
        console.log(body);
    }));
}

function SetRandomSong() {
    fetch("/api/randomSong").then(r => r.json().then(body => {
        const player = document.getElementById("mainAudio");
        console.log(player);
        console.log(body);
        player.src = "/api/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();
        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;
    }
}