Jump to content

Simple script listener/current track php/ajax


deaddred
 Share

Recommended Posts

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

 

$icecast_url='http://stream_url.com:8000';
$output = file_get_contents($icecast_url);
$search='#.*?Point /(.*?)M3U(.*?)(.*?)#si';
preg_match_all($search, $output, $matches);
$j=count($matches[0]);
for ($i=0;$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/

 




<br />
 $(document).ready(function() {<br />
      $("#responsecontainer").load("stream.php");<br />
   var refreshId = setInterval(function() {<br />
      $("#responsecontainer").load('stream.php?randval='+ Math.random());<br />
   }, 9000);<br />
   $.ajaxSetup({ cache: false });<br />
});<br />


Edited by deaddred
more info
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...