Android:MediaPlayer,如何获取音频流的属性?
我可以使用 MediaPlayer 界面成功收听音频流,但如何获取流的属性,例如当前比特率或流文本(许多流(例如在线收音机)包括当前播放的曲目)?
我试图找到这些信息,但找不到,如果这些东西可能存在,那么 android 开发网站上是否有一个列表,其中列出了各种可用的“属性”?
I can successfully listen to an audio stream with the MediaPlayer interface, but how can I get properties of the stream like the current bit rate, or the stream text (lots of streams like on line radios include the currently playing track)?
I tried to find this information but couldn't, if these things are possibly is there a list somewhere on the android dev site where the various available 'properties' are listed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,Android DEV 站点包含所有类信息 - 但有时很难找到您需要的信息。在这种情况下,检查该类的 java 源代码会非常有帮助。
快速查看 SDK,可以发现有一个
onInfoListener
接口,您可以在扩展MediaPlayer
的类中实现该接口。这需要您实现public boolean onInfo(MediaPlayer mp, int what, int extra)
。http://developer.android.com/reference/android/media/MediaPlayer .OnInfoListener.html 指出有一个what=
MEDIA_INFO_METADATA_UPDATE
。但是 - 检查谷歌会给出这样的想法:这永远不会被调用:-/
所以最终你只能靠自己了……
First, the Android DEV site is the site with all class information - but sometimes hard to find what you need. In that case, checking the java source of the class can be quite helpful.
From a quick look into the SDK, there is an
onInfoListener
interface, which you can implement in a class extendingMediaPlayer
. That needs you to havepublic boolean onInfo(MediaPlayer mp, int what, int extra)
implemented.http://developer.android.com/reference/android/media/MediaPlayer.OnInfoListener.html states there is a what=
MEDIA_INFO_METADATA_UPDATE
.But - checking google for that would give the idea that this never gets called :-/
So eventually you are on your own with that...
我可能会让这比需要的更难,但是您可以使用 Jlayer 解码流的帧 或其他一些 MP3 解码库来获取您正在寻找的信息。不确定是否有办法仅使用 Android sdk 来做到这一点。
I could be making this harder than it needs to be, but you can decode a frame of the Stream with Jlayer or some other MP3 decoding library to get the info you are looking for. Not sure if there is a way to do this with just the Android sdk.
如果您的流是shoutcast/icecast流,那么您可以使用 http://code.google 上的实用程序类.com/p/streamscraper/ 提取包括歌曲标题在内的元数据。
或者,您可以构建自己的元数据提取器。看看 http://www.smackfu.com/stuff/programming/shoutcast.html 了解更多信息。
If your stream is a shoutcast/icecast stream then you can use the utility class at http://code.google.com/p/streamscraper/ to extract the metadata including the song title.
Alternatively, you can build your own metadata extractor. Take a look at http://www.smackfu.com/stuff/programming/shoutcast.html for more info.