Reputation: 249
Is there a way to handle the Cannot play this video in android video view programatically.
Upvotes: 0
Views: 1126
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