javascript - 有没有办法获取 Icecast 流的广播状态?

标签 javascript php html icecast internet-radio

我正在使用 Icecast 2 进行直播和广播。

我希望当广播关闭而不是播放器显示下一个广播时间等其他内容,当广播打开时显示播放器进行流式传输。

最佳答案

如果您使用的是 Icecast 2.4.2,则可以使用 status-json.xsl 检查服务器上当前是否有任何流。

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

?>

关于javascript - 有没有办法获取 Icecast 流的广播状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32132613/

相关文章:

javascript - Cypress 有条件退出运行者/测试

c# - Javascript 与 C# 中的局部变量性能

html - 在 Bulma 中让列填充垂直空间?

php - 在 mac 中使用 cron 运行 php 脚本

php - 在 MYSQL 中添加两行的值并将它们组合成一行

javascript - SetTimeout 仅适用于桌面

java - 解析 XML,如果 CDATA 不包含 HTML 标记,则不返回任何字符串

javascript - 限制对页面的访问,除非来自特定页面

javascript - 使用 json 的 ExtJS 存储初始化失败

PHP fatal error : Allowed memory size of xxx bytes exhausted (tried to allocate XX bytes)