1

Below code is for play remote video of mine:

Uri uri = Uri.parse(URLPath);

vv.setVideoURI(uri);
vv.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
//play next one
}
});

vv.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return false;
}
});

It works for most of my devices.
But it does not works in some devices(Such as Samsung Galaxy S2).
I get the error code Error (200,-82).
I found it is MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK. What did it mean?
And how to avoid it?

brian
  • 6,802
  • 29
  • 83
  • 124

1 Answers1

2

MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK as doc says :

The video is streamed and its container is not valid for progressive playback i.e the video's index (e.g moov atom) is not at the start of the file.

The MediaPlayer often change to error state when playing video,and then prompt "can't play this video" dialog, so you have to handle these error via remembering the played time and replaying video after reset MediaPlayer engine.

You can implement OnErrorListener in your code for handling this type of errors as:

private MediaPlayer.OnErrorListener mOnErrorListener = new MediaPlayer.OnErrorListener() {

 public boolean onError(MediaPlayer mp, int what, int extra) {

   switch (what) {

    case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
         Toast.makeText(PlayerActivity.this, "MEDIA_ERROR_SERVER_DIED",
                                                    Toast.LENGTH_SHORT).show();                         
         return true;
    case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
        Toast.makeText(PlayerActivity.this,
                                            "MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK",
                                                    Toast.LENGTH_SHORT).show();
         break;
     case MediaPlayer.MEDIA_ERROR_UNKNOWN:
         Toast.makeText(PlayerActivity.this, "MEDIA_ERROR_UNKNOWN",
                                                    Toast.LENGTH_SHORT).show();
         break;
        }

         setProgressContainer(true, getString(R.string.msg_handle_error));
        int position=mVideoView.getCurrentPosition();
        if(position>0){
                   mCurPosition=position;
        }
         mVideoView.setVideoPath(mCurrentMediaUrl,position);

         return true;
         }

}; 
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • Another problem, this error is cause by different devices or by different Android versions? – brian May 28 '12 at 09:18
  • This is a good way to perform an action and log when this error is received, however, it doesn't not catch the error before the dialog appears. Not sure if you can do that. – digiphd Aug 07 '14 at 03:28