Android playing stream m3u using mediaPlayer

2019-04-16 21:22发布

I'm building an application that play streaming m3u file from web.

I'm using mediaPlayer class and it works. Here's the code :

String test_path = "http://cast.idvps.com:8000/djwirya.m3u";
        try {
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mediaPlayer.setDataSource(test_path);
            mediaPlayer.prepareAsync();
        } catch (IOException e) {Log.e("Error", "No Stream");}
        mediaPlayer.start();

It was working perfectly. But, after a whie I compiled it again, there's no sound.

pls help.... THX

2条回答
何必那么认真
2楼-- · 2019-04-16 22:03

This is a solution. Sorry I'm french but i'm think that should be ok with google translation.

Link for a solution

查看更多
Evening l夕情丶
3楼-- · 2019-04-16 22:11

You need to call mediaPlayer.setOnPreparedListener(this) before the prepareAsync(). This assumes that your activity or whatever has implemented the OnPreparedListener interface. Then you need a callback called onPrepared() in which you can call mediaPlayer.start().

The other thing you need to do is make sure you call mediaPlayer.release() somewhere when your app is ending. Inside of onPause() is probably a good idea.

查看更多
登录 后发表回答