Update track title and listener count from an Icecast2 server
HTML
<p> <span id="artist"></span> - <span id="track-title">Buffering</span> Listeners: <span id="listeners"></span> </p>
JavaScript
function radionomyTitle() {
// this is the URL of the json.xml file if you know the full direct url .
var url = 'http://api2.radionomy.com/currentsong.cfm?type=json&size=70&callmeback=yes&cover=yes&radiouid=d3dee3eb-0b86-4829-8acb-a14b9f6d61f8&jsonp';
// this is the radionomy currentsong api link .
var api = 'http://api2.radionomy.com/currentsong.cfm?type=json&size=70&callmeback=yes&cover=yes&radiouid=';
// this is you radionomy uid or stations if you can find it.
var uid = 'd3dee3eb-0b86-4829-8acb-a14b9f6d61f8';
// this is the radionomy url shortcut command.
var radionamyinfo = "http://api2.radionomy.com/currentsong.cfm?type=json&size=70&callmeback=yes&cover=yes&radiouid=" + uid + "&jsonp";
$.ajax({
type: 'GET',
url: radionamyinfo, // "radionamyinfo" var is default but use "url" if fail .
async: true,
jsonpCallback: 'GetPlayInfo',
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
// this is the element we're updating that will hold the track title
$('#artist').text(json['tracks']['artists'])
// this is the element we're updating that will hold the track title
$('#track-title').text(json['tracks']['title'])
// this is the element we're updating that will hold the listeners count
$('#listeners').text(json['tracks']['current']);
},
error: function(e) {
console.log(e.message);
}
});
}
$(document).ready(function() {
setTimeout(function() {
radionomyTitle();
}, 2000);
setInterval(function() {
radionomyTitle();
}, 1500); // we're going to update our html elements / player every 15 seconds
});