Kalai Arasi
Kalai Arasi

Reputation: 249

Handle "Cannot play this video" in VideoView

Is there a way to handle the Cannot play this video in android video view programatically.

Upvotes: 0

Views: 1126

Answers (1)

CROSP
CROSP

Reputation: 4617

You have to implement MediaPlayer.OnErrorListener And provide it to the following VideoView method

public void setOnErrorListener (MediaPlayer.OnErrorListener l)

It may look like this

MediaPlayer.OnErrorListener onErrorListener = new MediaPlayer.OnErrorListener()   
    {  
 @Override  
         public boolean onError(MediaPlayer mp, int what, int extra)   
         {  
        Log.e(getPackageName(), String.format("Error(%s%s)", what, extra));
              return true;  
         }  
};

mp the MediaPlayer the error pertains to
what the type of error that has occurred: MEDIA_ERROR_UNKNOWN MEDIA_ERROR_SERVER_DIED
extra an extra code, specific to the error. Typically implementation dependent. MEDIA_ERROR_IO MEDIA_ERROR_MALFORMED MEDIA_ERROR_UNSUPPORTED MEDIA_ERROR_TIMED_OUT

MEDIA_ERROR_UNSUPPORTED this constant represents state you are looking for.

Returns True if the method handled the error, false if it didn't. Returning false, or not having an OnErrorListener at all, will cause the OnCompletionListener to be called.

Upvotes: 1

Related Questions