TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 629
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 394
  • Total: 394

Radio Stream Status Indicator - On Air / Off Air [Shoutcast / IceCast]

Started by Zetan, April 25, 2008, 12:33:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zetan

This is an Online / Offline Status Indicator for Shoutcast / Icecast audio streams.
The original Request is HERE.

The original source of the code can be found HERE at my stream hosting company, Stream Solutions.

I have stripped the original code to display no other details than the Stream Status, Online and Offline, the original script has listener count, current track etc.. I didn't need those details as I use other scripts.




There are 5 parts:


  • The small block code that pulls the Status
  • a file named: radio_stats.php
  • a file named: config_radio.php
  • an image named: online.gif
  • an image named: offline.gif

The files need to be created by you and uploaded to the root directory of your server, along with the 2 images.
You need to edit the details to match the stream configuration.




Block Snippet

Block type: script block


<iframe name="AnyNameHere" src="radio_stats.php" style="background-color="#AnyColorHereOrDelete" width="70" height="59" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>





File 1

file name: radio_stats.php


  <?php
// Shoutcast Server Stats
// Parses shoutcasts xml to make an effective stats thing for any website
// Â©2004-2005 Daniel Brown http://www.gmtt.co.uk
// Please refer to the readme file for use.


// Add-On MAXLISTNERS insead of the / 10 MAXLISTENERS which was set, and the BITRATE add-on.
// Online and Offline graphics, and add-on code.
// Better HTML Script.

// Do Not Try To Edit This Only Unless You Know What You're Doing!!!!!!!

//---------------------------------------------------------
include('config_radio.php');

$scfp fsockopen("$scip"$scport, &$errno, &$errstr30);
 if(!
$scfp) {
  
$scsuccs=1;
echo
''.$scdef.' is Offline'
 }
if(
$scsuccs!=1){
 
fputs($scfp,"GET /admin.cgi?pass=$scpass&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");
 while(!
feof($scfp)) {
  
$page .= fgets($scfp1000);
 }

//---------------------------------------------------------
//define  xml elements
//---------------------------------------------------------
 
$loop = array("STREAMSTATUS");
 
$y=0;
 while(
$loop[$y]!=''){
  
$pageed ereg_replace(".*<$loop[$y]>"""$page);
  
$scphp strtolower($loop[$y]);
  $
$scphp ereg_replace("</$loop[$y]>.*"""$pageed);
// uncomment the next line to see all variables
//echo'$'.$scphp.' = '.$$scphp.'<br>';
  
$y++;
 }

//end intro xml elements
fclose($scfp);
}

//---------------------------------------------------------
//display stats
//---------------------------------------------------------
if($streamstatus == "1"){
//you may edit the html below, make sure to keep variable intact
echo'
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel=stylesheet href="" type="text/css">
<title>'
.$scdef.'</title>
</head>
<body text="" bgcolor="">
<center>

<img src="online.gif">
</body>
</html>'
;
}
//---------------------------------------------------------
//---------------------------------------------------------
if($streamstatus == "0"){
//you may edit the html below, make sure to keep variable intact
echo'
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel=stylesheet href="" type="text/css">
<title>Radio Server Is Offline</title>
</head>

<body text="" bgcolor="">
<center>

<img src="offline.gif">
</body>

</html>'
;
}
?>






File 2

File name: config_radio.php


<?php

         
$scip 
"StreamAddressHere";
$scport "PortNumberHere";                  
$scpass "ShoutcastPasswordHere";                 


?>






You need to create some Online / Offline  or  On Air / Off Air images and they need to be named:


  • online.gif
  • offline.gif
Note: I didn't write this script, if you have errors such as "fsock error". That is something you need to take up with your website hosting company. If they block the incoming data stream, there is nothing I can do about it.


This website is proudly hosted on Crocweb Cloud Website Hosting.