网站上有 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/