3

I am trying to stream m3u from url. The below code is working with an MP3 url but no with an m3u url.

This is how I initialize the player

private void initializeMediaPlayer() {
    mPlayer = new MediaPlayer();
    try {
        mPlayer.setDataSource(url);
    } catch (IllegalArgumentException | IllegalStateException | IOException e) {
        e.printStackTrace();
    }

    mPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
        public void onBufferingUpdate(MediaPlayer mp, int percent) {
            // Log.i("Buffering", "" + percent);
        }
    });
}

And this is my listener for play button

radioPlayButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        radioPlayButton.setBackgroundResource(R.drawable.ic_pause);

        mPlayer.prepareAsync();
        mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                mPlayer.start();
            }
        });
    }
});

I am testing in an Android 4.1.2 API 16 device and I am getting

E/MediaPlayer: Error (1,-2147483648)
xmoex
  • 2,602
  • 22
  • 36
user4292106
  • 441
  • 1
  • 11
  • 24
  • 1
    use [ExoPlayer](https://github.com/google/ExoPlayer), it's way better than MediaPlayer – lelloman Jan 29 '17 at 20:58
  • 1
    @lelloman I've just search for ExoPlayer and it doesn't support m3u format. https://google.github.io/ExoPlayer/supported-formats.html – user4292106 Jan 29 '17 at 21:06
  • as far as I know m3u are just text files with a list of media sources, it shouldn't be that hard to extract them – lelloman Jan 29 '17 at 21:12
  • and if I extract them how can I make it play with media player? – user4292106 Jan 29 '17 at 21:13
  • for m3u format you can look at the [wikipedia page](https://en.wikipedia.org/wiki/M3U), they basically contain a list of url with some headers – lelloman Jan 29 '17 at 21:15

0 Answers0