Android playing stream m3u using mediaPlayer
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);
开发者_如何学Go 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
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.
This is a solution. Sorry I'm french but i'm think that should be ok with google translation.
Link for a solution
精彩评论