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

标签 php audio audio-streaming shoutcast icecast

网站上有 5 个流。我需要检测这些流是否存在。如果没有,可以播放一些音频文件。

我正在使用 html5 播放流,流 url 如下所示:

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

我尝试了不同的方法,但似乎没有用。从未检测到流。

解决方案 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;  
        }

解决方案 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;
        }

你知道如何检查流是否存在吗?

最佳答案

您正在检查整个状态行,包括 HTTP 版本 HTTP/1.1。大多数服务器返回 HTTP/1.0。您只需要检查状态代码。

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

关于php - 如何检测 icecast/shoutcast 流是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15344196/

相关文章:

php - 从 ffmpeg shell_exec 命令中检索信息

php - 使用http客户端android studio以base64上传图片

php - 如何在php中按列对mysql数据进行排序?

.net - .net mcisendstring-使用资源而不是完整路径

java - 访问 Shoutcast 当前流信息

php - Laravel中未显示的错误

ios - 音频文件在后台播放时如何缩略图显示(IOS)?

Javascript:无法播放wav文件

java - 通过绑定(bind)的前台服务保持音频播放

c# - Windows Phone 8 - 播放流式音频(网络电台)