how do you get the artist and song title from MediaPlayer?

∥☆過路亽.° 提交于 2019-12-06 10:14:24

Quick research tells me that android.media.MediaPlayer only cares about stream data and nothing else. Therefore, if you want to also retrieve the stream's metadata (the station name, artist, song, etc.), you must do it separately, using a different object.

The android.media.MediaMetadataRetreiver class seems to be built to do exactly that. It looks like you should research the MetadataRetreiver.extractMetadata() function along with the METADATA_KEY_ARTIST and METADATA_KEY_TITLE keys.

Here is the MediaMetadataRetreiver API. Also, look at this previous StackOverflow question.

I am not an Android developer so I cannot guarentee my code is correct but I think it looks something like this:

MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
metaRetreiver.setDataSource(RADIO_STATION_URL)
String artist =  metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
String title = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);

(Full disclosure: code modified from here)

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