layout | title |
---|---|
page |
پخش زنده |
لطفا صبور باشید...
<script>
var status_url = 'http://server.mehsen.ir/status-json.xsl';
function ajax_get(url, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
try {
var data = JSON.parse(xmlhttp.responseText);
} catch(err) {
console.log(err.message + " in " + xmlhttp.responseText);
return;
}
callback(data);
}
};
if ("withCredentials" in xmlhttp) {
xmlhttp.open("GET", url, true);
} else if (typeof XDomainRequest != "undefined") {
xmlhttp = new XDomainRequest();
xmlhttp.open("GET", url);
} else {
throw new Error('CORS not supported');
}
xmlhttp.send();
}
String.prototype.toFaDigit = function() {
return this.replace(/\d+/g, function(digit) {
var ret = '';
for (var i = 0, len = digit.length; i < len; i++) {
ret += String.fromCharCode(digit.charCodeAt(i) + 1728);
}
return ret;
});
};
ajax_get(status_url, function(data) {
if (data["icestats"]["source"]) {
var started_milis_ago = Date.now() - Date.parse(data["icestats"]["source"]["stream_start_iso8601"]);
var html = "" + "در حال پخش زنده!" + "
"; html += '" + "در حال پخش: " + '' + data["icestats"]["source"]["title"] + '' + "
"; html += "" + "شروع پخش: " + '' + Math.floor(started_milis_ago / 60000).toString().toFaDigit() + '' + " دقیقه پیش" + "
"; html += "" + "تعداد شنوندگان: " + '' + data["icestats"]["source"]["listeners"].toString().toFaDigit() + '' + " نفر" + "
"; document.getElementById("stream").innerHTML = html; } else { var html = "" + "در حال حاضر پخش نداریم." + "
"; document.getElementById("stream").innerHTML = html; } }); setInterval(function(){ ajax_get(status_url, function(data) { if (data["icestats"]["source"]) { document.getElementById("listeners").innerHTML = data["icestats"]["source"]["listeners"].toString().toFaDigit(); var started_milis_ago = Date.now() - Date.parse(data["icestats"]["source"]["stream_start_iso8601"]); document.getElementById("started-mins-ago").innerHTML = Math.floor(started_milis_ago / 60000).toString().toFaDigit(); document.getElementById("now-playing").innerHTML = data["icestats"]["source"]["title"]; } }); }, 30000); </script>