Is it possible to get Icecast metadata from HTML5 audio element?

跟風遠走 提交于 2019-11-27 03:23:47

问题


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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6115531/is-it-possible-to-get-icecast-metadata-from-html5-audio-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!