2

I'm creating a list of videos which are played within a VideoView.

I want to catch the "Sorry, this video can't be played" error and just move on to the next video. The video-switching is handled within a onCompletionListener.

I already got the code for an onErrorListener from here but I just can't find how to trigger the "video is complete" event.

Any ideas?

Community
  • 1
  • 1
Ron
  • 22,128
  • 31
  • 108
  • 206
  • Do you want to catch errors and then play next video or do you just want the OnCompletionListener to be called? Have you set the .setOnCompletionListener for your media player? – Slickelito Feb 13 '13 at 15:46
  • i want the event to be triggered... – Ron Feb 13 '13 at 15:49

2 Answers2

2

You can do the same in the onErrorListener as you do in the onCompletionListener in onCompletion you set the video to the next one (somehow, i dont konw your implementation) then in on error use the same code (refactored into another function most likely). EG:

onError(....)
    if(error = watever error you need)
    functionNextVideo()

note the above is pseudo code.

But other than that onCompletionListener will not be triggered unless the video completes as it is supposed to.

Raigex
  • 1,205
  • 12
  • 32
1

As found in the source of the public interface OnErrorListener:

@return 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.
         */
        boolean onError(MediaPlayer mp, int what, int extra);

so the onCompletionListener will be invoked, if you return false or you dont handle the callback.

swisscoder
  • 129
  • 2
  • 11