简体   繁体   中英

How to get streaming audio metadata with MediaPlayer?

I'm building a radio player and I need to retrieve and update the metadata from the audio stream in real time.

I've tried with MediaMetadataRetriever but get null values:

MediaMetadataRetriever mmr;

url = "http://stream0.wfmu.org/freeform-128k";

if (Build.VERSION.SDK_INT >= 14)
    mmr.setDataSource(url, new HashMap<String, String>());
else
    mmr.setDataSource(url);

String out = "";
out += mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
out += "\n";
out += mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
out += "\n";
out += mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
out += "\n";
out += mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
out += "\n";

What's wrong?

And how can I know when the metadata changes? Using OnInfoListener 's onInfo ? Does it deal with the metadata I'm interested in (artist, title...) or the type or language code of the track, like MediaPlayer.TrackInfo ?

The metadata you are trying to access is a delivered via a SHOUTcast server (version 2). MediaMetadataRetriever doesn't support SHOUTcast metadata retrieval so you won't be able to use that. To my knowledge, there are no Java based libraries that support retrieval of SHOUTcast version 2 metadata so you will need to write the code yourself. See the guide here for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM