Android MediaPlayer not returning from prepareAsync

[亡魂溺海] 提交于 2019-12-11 05:14:42

问题


I'm getting the following back in Logcat starting MediaPlayer with a SPECIFIC URI. Normally every Uri, good or bad, will either play or come back with an error except this particular one.

I/MPS﹕ PrepAsync started
V/MediaPlayer﹕ message received msg=8, ext1=0, ext2=0
V/MediaPlayer﹕ unrecognized message: (8, 0, 0)
V/MediaPlayer﹕ callback application
V/MediaPlayer﹕ back from callback

... and hangs there.

I'm really just looking at how do I capture this conversation in an error handler but if someone knows the actual problem that's even better.

Source code FWIW:

mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
        public void onPrepared(MediaPlayer mediaPlayer) {
            mediaPlayer.start();
        }
    });
}

try {
    mediaPlayer.setDataSource(sUrl);
    mediaPlayer.prepareAsync();
} catch (Exception e) {
    Log.d(TAG, "Exception:"+e;
}

Also, I've tried creating an OnInfoListener, OnError and OnBufferingUpdateListener. These are never called. It's seems that mediaPlayer just goes away during onPrepareAsync.

Here is the URL if anyone is inspired to play with this.

http://54.196.206.122/entercom-koitfmaac-64

I just copy/pasted this into VLC to verify that the link is valid.

UPDATE: After looking at it more, if I wait long enough, eventually I get this:

I/dalvikvm﹕ threadid=3: reacting to signal 3
I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'

UPDATE: This problem as was pointed out by Shubhang Malviya was that I needed to use URI.parse as:

mMediaPlayer.setDataSource(mContext, Uri.parse("http://54.196.206.122/entercom-koitfmaac-64"));

回答1:


I thought It would be good If I share my implementation:

Try the following way of initialising your media player

try {
                    mMediaPlayer = new MediaPlayer();
                    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    mMediaPlayer.setOnPreparedListener(this);
                    mMediaPlayer.setOnCompletionListener(this);
                    mMediaPlayer.setOnErrorListener(this);
                    mMediaPlayer.setOnBufferingUpdateListener(this);
                    mMediaPlayer.setOnInfoListener(this);
                    mMediaPlayer.setOnSeekCompleteListener(this);
                    mMediaPlayer.setDataSource(mContext, Uri.parse("http://54.196.206.122/entercom-koitfmaac-64"));
                    mMediaPlayer.prepareAsync();
                } catch (IOException e) {
                 // reset media player
                }

Mine onPrepared(MediaPlayer mp) is getting called after only a few seconds and it is playing your Music File.

Also FYI "Couldn't open file on client side, trying server side" is not an error message, but a debug message from the MediaPlayer. Logcat always says this when trying to play a network video stream.



来源:https://stackoverflow.com/questions/27182805/android-mediaplayer-not-returning-from-prepareasync

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