Created
June 4, 2020 08:33
-
-
Save anthonyeden/d4df6ab7bbc47dbda88506f7f9640156 to your computer and use it in GitHub Desktop.
MetaRadio: Now Playing JS Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is an example HTML page, showing how you can use the 'FileJSONFTP' output along with a simple HTML page to show the current title/artist. | |
Simply setup the output 'FileJSONFTP' in MetaRadio Standalone, name the output file 'nowplaying.json', uncheck 'Output Raw Data?', and upload it to the same folder on your web server as this file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span id="metaradio-now-title"></span> | |
<span id="metaradio-now-artist"></span> | |
<span id="metaradio-now-artwork"></span> | |
<script> | |
// Setup our HTTP request | |
var xhr_metaradio_now = new XMLHttpRequest(); | |
// Setup our listener to process completed requests | |
xhr_metaradio_now.onload = function () { | |
// Process our return data | |
if (xhr_metaradio_now.status >= 200 && xhr_metaradio_now.status < 300) { | |
// Runs when the request is successful | |
data = JSON.parse(xhr_metaradio_now.responseText); | |
document.getElementById("metaradio-now-title").innerHTML = data['Title']; | |
document.getElementById("metaradio-now-artist").innerHTML = data['Artist']; | |
// Add iTunes image | |
if(data['iTunesArtwork_100'] != null) { | |
var img = document.createElement('img'); | |
img.src = data['iTunesArtwork_100']; | |
document.getElementById("metaradio-now-artwork").innerHTML = ''; | |
document.getElementById("metaradio-now-artwork").appendChild(img); | |
} | |
} | |
}; | |
function metaradio_now_fetch() { | |
// Fetch new now-playing data every 5 seconds | |
xhr_metaradio_now.open('GET', 'nowplaying.json'); | |
xhr_metaradio_now.send(); | |
} | |
metaradio_now_fetch(); | |
setInterval(metaradio_now_fetch, 5000); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment