2018-09-14 08:02:24 -04:00
|
|
|
function load() {
|
2018-09-20 10:39:23 -04:00
|
|
|
// track has ended
|
2018-09-14 08:02:24 -04:00
|
|
|
document.getElementById('player').addEventListener('ended', function() {
|
2018-09-20 10:39:23 -04:00
|
|
|
// shuffle
|
|
|
|
if (document.getElementById('shuffle').checked) {
|
2019-01-30 07:30:19 -05:00
|
|
|
var httpRequest;
|
|
|
|
httpRequest = new XMLHttpRequest();
|
2019-02-05 12:44:31 -05:00
|
|
|
httpRequest.onreadystatechange = function () {
|
2018-09-20 10:39:23 -04:00
|
|
|
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
|
|
|
|
if (httpRequest.status !== 200) { return; }
|
2019-02-05 12:44:31 -05:00
|
|
|
|
|
|
|
let track = JSON.parse(httpRequest.responseText);
|
2018-09-20 10:39:23 -04:00
|
|
|
change_track(track);
|
2019-01-30 07:30:19 -05:00
|
|
|
};
|
2019-02-05 12:44:31 -05:00
|
|
|
httpRequest.open('GET', api_uri + '/random', true);
|
2019-01-30 07:30:19 -05:00
|
|
|
httpRequest.send();
|
2018-09-14 08:02:24 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-05 11:23:41 -05:00
|
|
|
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 += '<option value="' + nav_items[i] + '">' + nav_items[i] + '</option>';
|
|
|
|
}
|
|
|
|
document.getElementById('albumList').innerHTML = html_str;
|
2019-02-07 09:33:35 -05:00
|
|
|
document.getElementById('trackList').innerHTML = '';
|
2019-02-05 11:23:41 -05:00
|
|
|
};
|
2019-02-25 13:40:36 -05:00
|
|
|
httpRequest.open('GET', api_uri + '?artist=' + select.value.replace('&', '%26'), true);
|
2019-02-05 11:23:41 -05:00
|
|
|
httpRequest.send();
|
|
|
|
}
|
2019-01-11 11:27:25 -05:00
|
|
|
|
2019-02-05 11:23:41 -05:00
|
|
|
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++) {
|
2019-02-05 11:33:58 -05:00
|
|
|
html_str += '<option value="' + nav_items[i].replace(/\d* - /, '') + '">' + nav_items[i] + '</option>';
|
2019-02-05 11:23:41 -05:00
|
|
|
}
|
|
|
|
document.getElementById('trackList').innerHTML = html_str;
|
|
|
|
};
|
2019-02-25 13:40:36 -05:00
|
|
|
httpRequest.open('GET', api_uri + '?artist=' + document.getElementById('artistList').value.replace('&', '%26') + '&album=' + select.value.replace('&', '%26'), true);
|
2019-02-05 11:23:41 -05:00
|
|
|
httpRequest.send();
|
2018-09-13 14:22:27 -04:00
|
|
|
}
|
|
|
|
|
2019-02-05 11:23:41 -05:00
|
|
|
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);
|
2019-02-05 12:44:31 -05:00
|
|
|
change_track(track);
|
2019-02-05 11:23:41 -05:00
|
|
|
};
|
2019-02-25 13:40:36 -05:00
|
|
|
httpRequest.open('GET', api_uri + '?artist=' + document.getElementById('artistList').value.replace('&', '%26') + '&album=' + document.getElementById('albumList').value.replace('&', '%26') + '&track=' + select.value.replace('&', '%26'), true);
|
2019-02-05 11:23:41 -05:00
|
|
|
httpRequest.send();
|
2018-09-14 08:02:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function change_track(track) {
|
2018-09-13 14:22:27 -04:00
|
|
|
let source = document.getElementById('stream');
|
2019-02-05 12:44:31 -05:00
|
|
|
source.src = track.streampath;
|
2018-09-13 14:22:27 -04:00
|
|
|
let player = document.getElementById('player');
|
|
|
|
player.load();
|
|
|
|
player.play();
|
2019-02-07 09:23:26 -05:00
|
|
|
document.getElementById('nowPlayingArtist').innerHTML = track.artist;
|
|
|
|
document.getElementById('nowPlayingAlbum').innerHTML = track.album;
|
|
|
|
document.getElementById('nowPlayingTitle').innerHTML = track.title;
|
2018-09-20 10:39:23 -04:00
|
|
|
|
2019-02-05 13:04:10 -05:00
|
|
|
document.getElementById('albumCover').firstChild.src = track.coverart;
|
2018-09-13 14:22:27 -04:00
|
|
|
}
|