2015-08-21 4 views

Répondre

1

Si vous utilisez Icecast 2.4.2, vous pouvez utiliser status-json.xsl pour vérifier si un flux est présent sur le serveur.

<?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)); 

?>