Santhosh
Santhosh

Reputation: 5016

Get online radio song details in Android

I have to stream and play a third party radio station in my Android app. Here is my code to do so and it works well.

        Uri myUri = Uri.parse(RADIO_STATION_URL);
        try {
            this.mp = new MediaPlayer();

            mp.setDataSource(this, myUri);
            mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mp.setOnPreparedListener(this);
            mp.setOnBufferingUpdateListener(this);
            mp.setOnErrorListener(this);
            mp.setOnCompletionListener(this);
            mp.prepareAsync();
            mp.setScreenOnWhilePlaying(true);

        } catch (Throwable t) {
            logcat t details
        }

and starting the mediaplayer when the media file is ready for playback. Is there any way to get currently playing song details too? (like song, track names etc).

Upvotes: 0

Views: 2805

Answers (1)

Alexis C.
Alexis C.

Reputation: 93842

If you're using API 10 or more, you can use the MediaMetadataRetriver API.

It would be something like this :

MediaMetadataRetriever mMediaMetaDataRetriever = new MediaMetadataRetriever();
mMediaMetaDataRetriever.setDataSource(myContext, myUri)
String albumName =  mMediaMetaDataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM;
String artistName =  mMediaMetaDataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST;
String titleName = mMediaMetaDataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);

May you can have a look at this thread too.

Upvotes: 2

Related Questions