是否可以从 HTML5 音频元素获取 Icecast 元数据?
我正在使用音频元素从 Icecast 服务器流式传输 ogg 源。音频元素是否提取冰冷的元数据并且有没有办法通过 JavaScript 访问它?
基本上,我想显示我正在播放的广播电台的“当前播放”信息。我有什么选择?
谢谢!
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?
Basically, I want to show "currently playing" information of a radio station I am streaming. What are my options?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您的 HTML5 元素只知道流数据,甚至没有发出适当的请求来获取元数据。
请参阅以下帖子:
开发icecast服务器的客户端
拉轨道使用 PHP 来自音频流的信息
http://www.smackfu.com/stuff/programming/shoutcast.html
现在,这无论如何都不是不可能的。您只需在服务器端进行即可。 (特别请参阅第二个链接。)
我还应该指出,在成熟的 SHOUTcast 服务器上(尚未使用 Icecast 进行测试,但值得一试)会生成“7.html”,其中包含有关听众数量的数据、最大听众数、峰值听众数、立体声/单声道、比特率和当前曲目名称(以逗号分隔值)。像这样:
2,1,33,625,2,128,J Mascis - Not Enough
如果您可以获取
http://yourstreamingserver:port/7.html
,那么您可以获得这个数据很容易。No, your HTML5 elements are only aware of the stream data, and aren't even making the appropriate request to fetch the metadata.
See these posts:
Developing the client for the icecast server
Pulling Track Info From an Audio Stream Using PHP
http://www.smackfu.com/stuff/programming/shoutcast.html
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:
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.对于 Ogg 容器流(Vorbis 和 Opus),至少 Firefox 支持对元数据的 javascript 访问。目前,这只是“供应商特定的”Javascript API:
audio.mozGetMetadata();
另一方面,如果您使用 Icecast 2.4.1,您可以通过 JSON API 独立访问元数据。正如其他评论中指出的那样,缺乏同步也是适用的。但它通常“足够接近”。
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();
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.