Android MediaPlayer takes too long to get ready

Hey, I'm using MediaPlayer to play a regular ShoutCast stream. The code is simple with prepareAsync () and a handler to start playback. Although it works flawlessly with some streams, such as DI.FM or ETN.FM (http://u10.di.fm:80/di_progressive), with others (http://mp3.wpsu.org:8000/) t go through a state of readiness. Other listeners are not called.

//Uri streamUri = Uri.parse("http://u10.di.fm:80/di_progressive"); /* works */
Uri streamUri = Uri.parse("http://mp3.wpsu.org:8000/"); /* stuck on prepare state */
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
    public void onPrepared(MediaPlayer mp) {
        mp.start();
    }
});
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(this.getBaseContext(), streamUri);
mediaPlayer.prepareAsync();

Any feedback is appreciated!

+5
source share
2 answers

I think there are compatibility issues with the end of the server. This is rather strange, because the emulator does this in my case - it’s just not on my Froyo Galaxy S, even if it's the same version of the API.

, HTTP, . , , , , "Copyright 1998 - 2004" ... , .

( ) StreamProxy, 2.1 , , . , , , ...

, 2.2, : 2.1, 2.2

+2

, MP "" (), reset(). MP , , , . , MP . Im prepare(), prepareAsync(). . :

private void actionCancel(){
            try {
                mp.setDataSource(new String());
            } catch (Exception e) {
                e.printStackTrace();
                android.util.Log.d(TAG,"actionCancel(): mp.setDataSource() exception");
                mp.reset();
            }
}

4me.
, :

    @Override
    public void onBufferingUpdate(final MediaPlayer mp, final int percent) {

        if (!mp.isPlaying()){
//          android.util.Log.d(TAG,"onBufferingUpdate(): onBufferingUpdateCount = "+onBufferingUpdateCount);
            if (onBufferingUpdateCount>MAX_BUFFERING_UPDATES_AT_PREPARING_STATE)
                restartMP();
            onBufferingUpdateCount++;
            return;
        }
      }

, . 10 , MP , :

private void restartMP(){
        if (mp!=null)
            if (mpState==MediaPlayerState.Preparing)
                actionCancel();
            else
                mp.reset();
    else
        mp = new MediaPlayer();
        mpState = MediaPlayerState.Idle;
        onBufferingUpdateCount=0;
        //isRequestCancelled=false;
        requestTrackInfoStartedAt=0;
        requestPlay();
}

note. MediaPlayerState - , "". mpState - / , MediaPlayerState. prepareAsync() im mpState MediaPlayerState. , IMP MediaPlayerState.Started .

+2

All Articles