Android playing stream m3u using mediaPlayer

旧时模样 提交于 2019-12-06 10:02:59

问题


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


回答1:


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.




回答2:


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

Link for a solution



来源:https://stackoverflow.com/questions/6730702/android-playing-stream-m3u-using-mediaplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!