ExoPlayer: get songs metadata from HTTP stream

Anton Balashov picture Anton Balashov · Nov 19, 2015 · Viewed 11.6k times · Source

I use the following code to play a music stream through ExoPlayer:

        exoPlayer = ExoPlayer.Factory.newInstance(numRenderers, minBufSize, maxBufSize);
        String url = Helper.getPr().getString("url", "http://mp3.nashe.ru:80/ultra-128.mp3");
        Uri uri = Uri.parse(url);
        Log.i(TAG, "Going to open " + url);
        Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
        DataSource dataSource = new DefaultUriDataSource(getApplicationContext(), USER_AGENT);
        ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);
        audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);
        exoPlayer.addListener(this);
        exoPlayer.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME, volume);
        exoPlayer.prepare(audioRenderer); 
        exoPlayer.setPlayWhenReady(true);

I can't find any info on how to get metadata like artist and name of the current song. Is it possible to get the metadata and if yes, how?
Thanks a lot.

Answer

Renaud Boulard picture Renaud Boulard · Nov 24, 2015

There are many types of metadata in many types of media, It's depending on your stream. But currently Exoplayer itself, only parse metadata from HLS streams (HTTP Live Streaming) they get ID3 data from the stream.

As you can see on there github repository issue,this is the current state of metadata in Exoplayer lib (August 2015): https://github.com/google/ExoPlayer/issues/704

If it's your stream case, I will recommend you to download the Exoplayer demo on github (https://github.com/google/ExoPlayer/tree/master/demo). One of the examples in the demo display stream ID3 metadata on LogCat.

If it's not your case, nothing will help you in ExoPlayer lib right now.

But there is an alternative solution, which I have used for a radio stream application, and it work well:

IcyStreamMeta to get meta data from online stream radio :

Getting metadata from SHOUTcast using IcyStreamMeta

but not sure it will work with simple mp3 file.