function load() { // track has ended document.getElementById('player').addEventListener('ended', function() { // shuffle if (document.getElementById('shuffle').checked) { fetch(api_uri + '/random').then(function(response) { return response.json(); }).then(function(json) { change_track(json); }); } }); } function select_artist(select) { let params = { artist: select.value, }; let query = Object.keys(params) .map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k])) .join('&'); fetch(api_uri + '?' + query).then(function(response) { return response.json(); }).then(function(json) { let html_str = ''; for (let i = 0; i < json.length; i++) { html_str += ''; } document.getElementById('albumList').innerHTML = html_str; document.getElementById('trackList').innerHTML = ''; }); } function select_album(select) { let params = { artist: document.getElementById('artistList').value, album: select.value, }; let query = Object.keys(params) .map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k])) .join('&'); fetch(api_uri + '?' + query).then(function(response) { return response.json(); }).then(function(json) { let html_str = ''; for (let i = 0; i < json.length; i++) { html_str += ''; } document.getElementById('trackList').innerHTML = html_str; }); } function select_track(select) { let params = { artist: document.getElementById('artistList').value, album: document.getElementById('albumList').value, discnumber: select.selectedOptions[0].dataset.discnumber, tracknumber: select.selectedOptions[0].dataset.tracknumber, }; let query = Object.keys(params) .map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k])) .join('&'); fetch(api_uri + '?' + query).then(function(response) { return response.json(); }).then(function(json) { change_track(json); }); } function change_track(track) { let params = { artist: track.artist, album: track.album, discnumber: track.discnumber, tracknumber: track.tracknumber, }; let query = Object.keys(params) .map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k])) .join('&'); let source = document.getElementById('stream'); source.src = document.location.href + '/stream?' + query; 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 = document.location.href + 'coverart?' + query; }