简体   繁体   English

如何检测是否存在icecast / shoutcast流?

[英]How to detect if a icecast / shoutcast stream exists or not?

There are 5 streams on a website. 网站上有5个流。 I need to detect if these streams exist. 我需要检测这些流是否存在。 If not, there are some audio files to play instead. 如果没有,则可以播放一些音频文件。

I'm using html5 to play the stream and stream urls look like this : 我正在使用html5来播放流,流网址看起来像这样:

http://locus.creacast.com:9001/StBaume_grotte.ogg http://locus.creacast.com:9001/StBaume_grotte.ogg

I've tried different things but it doesn't seem to work. 我尝试了不同的东西,但它似乎没有用。 Streams are never detected. 从未检测到流。

Solution 1 : Here, i simply tried to check if file exists. 解决方案1:在这里,我只是试图检查文件是否存在。

if (file_exists($stream_1)) {
             $debug_output_stream_1 = "Le fichier $stream_1 existe.";
             $erreur_404_Stream_1 = true;  
        } else {
             $debug_output_stream_1 =  "Le fichier $stream_1 n'existe pas.";
             $erreur_404_Stream_1 = false;  
        }

Solutions 2 : I try to detect a 404 error 解决方案2:我尝试检测404错误

 $file_headers_1 = @get_headers($stream_1);
        if($file_headers_1[0] == 'HTTP/1.1 404 Not Found') {
            $debug_output_stream_1 = "StBaume_sommet.ogg : L'URL n'existe pas.";
            $erreur_404_Stream_1 = true;  
        }
        else {
            $debug_output_stream_1 = "StBaume_sommet.ogg : L'URL existe.";
            $erreur_404_Stream_1 = false;
        }

Do you know how to check if streams exist ? 你知道如何检查流是否存在?

You are checking the entire status line, including the HTTP version HTTP/1.1 . 您正在检查整个状态行,包括HTTP版本HTTP/1.1 Most servers return HTTP/1.0 . 大多数服务器返回HTTP/1.0 You need to check the status code only. 您只需要检查状态代码。

if (strpos($file_headers_1[0], '200 OK') === false) {
    // error occurred
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM