Java 错误时触发VideoView onCompletion事件

Java 错误时触发VideoView onCompletion事件,java,android,listener,android-mediaplayer,android-video-player,Java,Android,Listener,Android Mediaplayer,Android Video Player,我正在创建在视频视图中播放的视频列表 我想捕捉“抱歉,此视频无法播放”错误,然后继续下一个视频。视频切换在CompletionListener的中处理 我已经从中获得了onErrorListener的代码,但我就是找不到如何触发“视频已完成”事件 有什么想法吗?您可以在onErrorListener中执行与在onCompletionListener中相同的操作 在onCompletion中,您将视频设置为下一个(不知何故,我不知道您的实现),然后在出错时使用相同的代码(最有可能重构为另一个函数)

我正在创建在
视频视图中播放的视频列表

我想捕捉“抱歉,此视频无法播放”错误,然后继续下一个视频。视频切换在CompletionListener的
中处理

我已经从中获得了
onErrorListener
的代码,但我就是找不到如何触发“视频已完成”事件


有什么想法吗?

您可以在onErrorListener中执行与在onCompletionListener中相同的操作 在onCompletion中,您将视频设置为下一个(不知何故,我不知道您的实现),然后在出错时使用相同的代码(最有可能重构为另一个函数)。 例如:

注意上面是伪代码


但除此之外,除非视频按预期完成,否则不会触发onCompletionListener。

如公共接口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);

因此,如果返回false或不处理回调,将调用onCompletionListener。

是要捕获错误然后播放下一个视频,还是只想调用onCompletionListener?是否为媒体播放器设置了.setOnCompletionListener?我希望触发事件。。。
@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);