View Single Post
Old 1st March 2019, 15:26   #17
stereoscenic
Junior Member
 
Join Date: Dec 2013
Posts: 18
Here's how I do it for now playing & listener count:

<script>
var np = {};
np.parse = function(r){

var t = r.streams[3].songtitle.split(" - ");
document.getElementById('trackartist').innerHTML = t[0];
document.getElementById('tracktitle').innerHTML = t[1];
document.getElementById('nolisteners').innerHTML = (r.streams[2].currentlisteners + r.streams[3].currentlisteners) + ' <div id=listeners-label>Listeners</div>';

}
np.jsonp = function(){
var s = document.createElement("script");
s.src="http://yourserver.com/statistics?json=1&callback=np.parse";
document.body.appendChild(s);
document.body.removeChild(s);
setTimeout( function(){ window.requestAnimationFrame( np.jsonp ) || np.jsonp(); }, 3e4 );
}
np.jsonp();
// setInterval(np.jsonp, 3e4);
</script>

Note: this checks the server every 30 seconds. I use "requestanimationframe" to pause the script when the browser has a different tab active. you could remove that whole line and use the basic "setInterval" method at the end there.
stereoscenic is offline   Reply With Quote