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 = JSON.parse(httpRequest.responseText); change_track(track); }; httpRequest.open('GET', api_uri + '/random', 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; document.getElementById('trackList').innerHTML = ''; }; httpRequest.open('GET', api_uri + '?artist=' + select.value.replace('&', '%26'), 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.replace('&', '%26') + '&album=' + select.value.replace('&', '%26'), 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); change_track(track); }; 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); httpRequest.send(); } function change_track(track) { let source = document.getElementById('stream'); source.src = track.streampath; let player = document.getElementById('player'); player.load(); player.play(); document.getElementById('nowPlayingArtist').innerHTML = track.artist; document.getElementById('nowPlayingAlbum').innerHTML = track.album; document.getElementById('nowPlayingTitle').innerHTML = track.title; document.getElementById('albumCover').firstChild.src = track.coverart; }