javascript 是否可以从 HTML5 音频元素获取 Icecast 元数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6115531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to get Icecast metadata from HTML5 audio element?
提问by Roman Semko
I am using audio element to stream an ogg source from an icecast server. Does the audio element extract icy metadata and is there a way to access it through javascript?
我正在使用音频元素从 icecast 服务器流式传输 ogg 源。音频元素是否提取冰冷的元数据,有没有办法通过 javascript 访问它?
Basically, I want to show "currently playing" information of a radio station I am streaming. What are my options?
基本上,我想显示我正在播放的广播电台的“当前播放”信息。我有哪些选择?
Thanks!
谢谢!
采纳答案by Brad
No, your HTML5 elements are only aware of the stream data, and aren't even making the appropriate request to fetch the metadata.
不,您的 HTML5 元素只知道流数据,甚至没有发出适当的请求来获取元数据。
See these posts:
看到这些帖子:
Now, this isn't impossible by any means. You just have to do it server-side. (See that second link in particular.)
现在,这无论如何都不是不可能的。你只需要在服务器端做。(特别参见第二个链接。)
I should also point out that on a full-blown SHOUTcast Server (haven't tested with Icecast, but its worth a try) generates "7.html" which contains data on the number of listeners, max listeners, peak listeners, stereo/mono, bitrate, and current track name as comma-separated values. Like this:
我还应该指出,在成熟的 SHOUTcast 服务器上(尚未使用 Icecast 进行测试,但值得一试)生成“7.html”,其中包含有关听众数量、最大听众、峰值听众、立体声/单声道、比特率和当前轨道名称作为逗号分隔值。像这样:
2,1,33,625,2,128,J Mascis - Not Enough
2,1,33,625,2,128,J Mascis - Not Enough
If you can fetch http://yourstreamingserver:port/7.html
, then you can get this data very easily.
如果您可以 fetch http://yourstreamingserver:port/7.html
,那么您可以非常轻松地获取这些数据。
回答by TBR
In case of an Ogg container stream (So both Vorbis and Opus), at least Firefox supports javascript access to the metadata. This is currently only "vendor specific" Javascript API: audio.mozGetMetadata();
对于 Ogg 容器流(Vorbis 和 Opus 都是如此),至少 Firefox 支持 javascript 访问元数据。这目前只是“特定于供应商的”Javascript API:audio.mozGetMetadata();
On the other hand if you go with Icecast 2.4.1 you can access metadata independently through a JSON API. Lack of synchronization as pointed out in other comments applies. It's usually "close enough" though.
另一方面,如果您使用 Icecast 2.4.1,您可以通过 JSON API 独立访问元数据。其他评论中指出的缺乏同步适用。不过,它通常“足够接近”。