[英]Android MediaPlayer Error Feedback
I am using MediaPlayer
in my code to play video. 我在代码中使用MediaPlayer
播放视频。
This is the code : 这是代码:
mp.setDataSource(source);
mp.setOnCompletionListener(this);
mp.setOnErrorListener(this);
mp.prepareAsync();
In some cases the video is not playing(and if i call mp.getDuration();
i get fail) and instead of getting OnError
feedback i am getting OnCompletion
feedback, and i can't know if any problem occurs. 在某些情况下,视频无法播放(如果我调用mp.getDuration();
我会失败),而不是获得OnError
反馈,而是获得OnCompletion
反馈,而且我不知道是否发生任何问题。
And some times i get OnError
function called. 有时我会调用OnError
函数。
Any idea how i can check if the mediaplayer was fail in the OnCompletion
function? 任何想法,我怎么可以检查Mediaplayer是否在OnCompletion
函数中失败?
According to the Docs, onErrorListener
returns: 根据文档, onErrorListener
返回:
True if the method handled the error, false if it didn't. 如果该方法处理了错误,则为true,否则为false。 Returning false, or not having an OnErrorListener at all, will cause the OnCompletionListener to be called. 返回false或完全没有OnErrorListener,将导致调用OnCompletionListener。
So your onCompletion
is being called when onError
returns false. 因此,当onError
返回false时,将调用您的onCompletion
。
Your implementation of onErrorListener
should return true to avoid onCompletion
to be called. 您的onErrorListener
实现应返回true,以避免调用onCompletion
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.