开发者

Android: MediaPlayer, How to get properties of an audio stream?

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 vario开发者_开发问答us available 'properties' are listed?


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 extending MediaPlayer. That needs you to have public 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...


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜