How to intercept the "Cannot play video" dialog while working with streaming or networked video?
I tried the following and was able to display my custom error message. But on top of that I am still getting Android MediaPlayer error dialog "Cannot play video".
I have implemented setOnErrorListener
for MediaPlayer and overwrote the onError
method with logic to show my error message and I am returning true
to let Android know I am handling this error. My code is as follows
mediaPlayer.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
if (!mediaActivity.isFinishing()) {
mVideoView.stopPlayback();
mediaPlayer.release();
showErrorDialog(false);
}
return true;
}
});
Here is the my working code!
videoView = (VideoView) findViewById(R.id.videoViewPopup);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(this.mediaURL); // Put your URL here
videoView.setMediaController(mc);
videoView.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Utils.showAlertDialog(Constants.NETWORK_ERROR_MESSAGE, Constants.NETWORK_ERROR_TITLE, VideoPopupActivity.this);
return true;
}
});
videoView.setVideoURI(video);
videoView.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With