PDA

View Full Version : Simple script listener/current track php/ajax



deaddred
11-25-2014, 11:06 PM
Not sure how efficient this script is but atm while I'm still gathering software for my station I got these two scripts to work together to display the listener count and current track and refresh the info automatically every 5 or so seconds.

The php script. Put this into stream.php file


<?php
$icecast_url='http://stream_url.com:8000';
$output = file_get_contents($icecast_url);
$search='#<div class="newscontent">.*?Point /(.*?)<.*?href="(.*?)">M3U<.*?Listeners.*?class="streamdata">(.*?)<.*?Song:.*?class="streamdata">(.*?)<.*?</div>#si';
preg_match_all($search, $output, $matches);
$j=count($matches[0]);
for ($i=0;$i<$j; $i++) {
$point_name=$matches[1][$i];
$pount_m3u=$icecast_url.$matches[2][$i];
$point_listners_count=$matches[3][$i];
$point_current_song=$matches[4][$i];
//

echo 'Listeners: '.$point_listners_count.' ';
echo 'Playing: '. $point_current_song.'';
}
?>


The AJAX script I got here http://www.brightcherry.co.uk/scribbles/jquery-auto-refresh-div-every-x-seconds/


<html>
<head>
<!-- For ease i'm just using a JQuery version hosted by JQuery- you can download any version and link to it locally -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$("#responsecontainer").load("stream.php");
var refreshId = setInterval(function() {
$("#responsecontainer").load('stream.php?randval='+ Math.random());
}, 9000);
$.ajaxSetup({ cache: false });
});
</script>
</head>
<body></body>

deaddred
11-25-2014, 11:21 PM
You can see it working here http://futureassassin.com/

jarred89
01-26-2015, 06:57 AM
Hello,

I am wanting an icecast Now Playing script on my website. I am stuck on how to install this one onto my website. Can you please explain it. It keeps coming up with an error on line 3.