我正在创建一个在VideoView
中播放的视频列表。
我想抓住"对不起,无法播放此视频"的错误,然后继续下一个视频。视频切换是在CCD_ 2内处理的。
我已经从这里得到了onErrorListener
的代码,但我只是找不到如何触发"视频已完成"事件。
有什么想法吗?
您可以在onErrorListener中执行与在onCompletionListener中相同的操作在onCompletion中,你将视频设置为下一个(不知何故,我不知道你的实现),然后在出错时使用相同的代码(很可能重构为另一个函数)。例如:
onError(....)
if(error = watever error you need)
functionNextVideo()
注意,上面是伪代码。
但除此之外,除非视频按预期完成,否则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将被调用。