18

Our app plays a set of videos, sometimes we are getting can't play this video alert message.

We are either playing video from sd card or streaming if that video is not yet downloaded. Mostly, error arises while streaming with slow internet connection.

I understood few causes of this error from reading some posts and blogs.

But, now I want to play the next video when the error occurs without showing that error message.

I used the below listener for that ,

video.setOnErrorListener(new OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.d("video", "setOnErrorListener ");
                return false;
            }
        });

Method got invoked when the error arises, but can't stop showing that alert message.

Is there any way to stop showing that alert message?

Thanks in advance.

Jonik
  • 80,077
  • 70
  • 264
  • 372
Sreedhu Madhu
  • 2,480
  • 2
  • 30
  • 40
  • Adding an `onPreparedListener()` like in the selected answer to this [post](http://stackoverflow.com/questions/18482018/mediaplayer-error-38-0) may help you. – Koh Jan 15 '15 at 18:41

1 Answers1

68

Returning false or not having an OnErrorListener at all will cause the OnCompletionListener to be called.

So return true instead of false from the function and no error will be shown, i.e.

video.setOnErrorListener(new OnErrorListener() {
    @Override
    public boolean onError(MediaPlayer mp, int what, int extra) {
        Log.d("video", "setOnErrorListener ");
        return true;
    }
});

For more info see Android Document

mcarton
  • 27,633
  • 5
  • 85
  • 95
Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
  • still getting alert message – Sreedhu Madhu Jun 24 '14 at 11:55
  • Works a treat. I found this a great fix for simulators where playing MP4 files on certain versions of Android would throw this error. The MP4 file in question was being used as a splash screen. – Daniel Maclean Sep 24 '15 at 13:48
  • how can you prevent to display 'can't play this video' alert message? i mean how will the video will play and the alert message will not show? it only doesn't show the alert message. – Kairi San Jan 13 '16 at 07:31