[英]How to display Now Playing in my website with Icecast2 and Liquidsoap
我在網上找不到更好的答案,即使是 Liquidsoap 的文檔也無濟於事。 我想要發生的是獲取我的流媒體服務器(icecast)中正在播放的當前歌曲名稱和藝術家。 我在一些論壇上發現他們能夠做到,但他們沒有解釋它是如何做到的,這是他們使用的liquidsoap腳本:
def apply_metadata(m) =
title = m["title"]
artist = m["artist"]
album = m["album"]
[("artist","#{artist}"),("title","#{album} - #{title}")]
end
centovacast.callback_autodj := fun(s) -> map_metadata(apply_metadata,s)
我相信這個腳本也只適用於 centova 和 autodj。 雖然我不使用這些技術(我使用的是 Ubuntu 16.04、Icecast2、Liquisoap、PHP、HTML5/CSS),但使用我目前使用的工具可以做到嗎?
我不確定您為什么要將源客戶端拖到這個中。
發送到 Icecast 掛載點的正確流將具有當前播放音頻的元數據。
這已在別處指出。 Icecast 自 2.4.1 起提供了正確的 JSON 元數據導出。
從網站內查詢 JSON 是一個非常已解決的問題,並且被認為是有興趣的讀者的練習。
你為什么不直接在icecast上搶這個?
PHP:
function get_icecast_info($server_ip, $server_port, $admin_user, $admin_password) {
$index = @file_get_contents("http://".$admin_user.":".$admin_password."@".$server_ip.":".$server_port."/admin/stats.xml");
if($index) {
$xml = new DOMDocument(); if(!$xml->loadXML($index)) return false; $arr = array(); $listItem = $xml->getElementsByTagName("source");
foreach($listItem as $element) {
if($element->childNodes->length) {
foreach($element->childNodes as $i){ $arr[$element->getAttribute("mount")][$i->nodeName] = $i->nodeValue; }
}
}
return $arr;
} return false;
}
這是輸出(數組):
$arr = get_icecast_info($ice_host, $ice_aport, $ice_user, $ice_pass);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.