3

I am using Icecast 2 for live streaming and broadcasting.

I want that when broadcasting is off instead of player show something else like next broadcast time and when broadcast is on then show player for streaming.

ePirat
  • 1,068
  • 11
  • 20
Hamza Khan
  • 191
  • 15

1 Answers1

3

If you are using Icecast 2.4.2 you can use the status-json.xsl, to check if any stream is currently up on the server.

<?php

/* Checks if any stream is running on the Icecast server at the 
 * specified URL.
 * Returns TRUE if running, FALSE if not.
 *
 * It uses the status-json.xsl which is available since Icecast 2.4,
 * although it was sometimes invalid before Icecast 2.4.1
 * If connecting to the Icecast server fails, GETing the JSON fails or
 * JSON decoding fails, this function will report FALSE.
 */
function is_stream_running($icecast_host, $icecast_port) {
  $status_url = "http://{$icecast_host}:{$icecast_port}/status-json.xsl";
  $status_dat = @file_get_contents($status_url);
  if ($status_dat === FALSE) {
    return FALSE;
  }
  $status_arr = json_decode($status_dat, true);
  if ($status_arr === NULL || !isset($status_arr["icestats"])) {
    return FALSE;
  }
  return ($status_arr["icestats"]["source"]) ? true : false;
}

var_dump(is_stream_running("localhost", 8000));

?>
ePirat
  • 1,068
  • 11
  • 20