function load() {
// track has ended
document.getElementById('player').addEventListener('ended', function() {
// shuffle
if (document.getElementById('shuffle').checked) {
var httpRequest;
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
if (httpRequest.status !== 200) { return; }
let track = httpRequest.responseText;
change_track(track);
};
httpRequest.open('GET', '/musik/get_shuffle', true);
httpRequest.send();
}
});
}
function select_artist(select) {
var httpRequest;
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
if (httpRequest.status !== 200) { return; }
nav_items = JSON.parse(httpRequest.responseText);
let html_str = '';
for (let i = 0; i < nav_items.length; i++) {
html_str += '';
}
document.getElementById('albumList').innerHTML = html_str;
};
httpRequest.open('GET', api_uri + '?artist=' + select.value, true);
httpRequest.send();
}
function select_album(select) {
var httpRequest;
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
if (httpRequest.status !== 200) { return; }
nav_items = JSON.parse(httpRequest.responseText);
let html_str = '';
for (let i = 0; i < nav_items.length; i++) {
html_str += '';
}
document.getElementById('trackList').innerHTML = html_str;
};
httpRequest.open('GET', api_uri + '?artist=' + document.getElementById('artistList').value + '&album=' + select.value, true);
httpRequest.send();
}
function select_track(select) {
var httpRequest;
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
if (httpRequest.status !== 200) { return; }
let track = JSON.parse(httpRequest.responseText);
let source = document.getElementById('stream');
source.src = track.streampath;
let player = document.getElementById('player');
player.load();
player.play();
document.getElementById('nowPlaying').innerHTML = track.title;
};
httpRequest.open('GET', api_uri + '?artist=' + document.getElementById('artistList').value + '&album=' + document.getElementById('albumList').value + '&track=' + select.value, true);
httpRequest.send();
}
function change_track(track) {
let source = document.getElementById('stream');
source.src = '/musik/stream' + encodeURIComponent(track);
let player = document.getElementById('player');
player.load();
player.play();
document.getElementById('nowPlaying').innerHTML = track;
let arr = track.split('/');
let art = document.getElementById('albumCover');
art.firstChild.src = '/musik/album_cover' + arr.slice(0, arr.length-1).join("/") + '/folder.jpg';
}