如何检测VideoView是在播放视频还是在缓冲? [英] How to detect if VideoView is playing video or Buffering?
问题描述
如何检测VideoView是在播放视频还是在缓冲?
我想显示一个弹出窗口,说视频正在缓冲.
How to detect if VideoView is playing video or Buffering?
I want to display a pop-up saying video is buffering.
在android API级别17中,有一个回叫setOnInfoListener
可以为我提供此信息,但是我正在使用API级别15(android ICS).
In android API level 17 there is a call back setOnInfoListener
that can provide me this information but i am using API level 15 (android ICS).
我也看到了这个问题"检测是否有VideoVIew正在缓冲 ",但建议的解决方案适用于MediaPlayer
而不适用于VideoView
.
I have also seen this question "Detect if a VideoVIew is buffering" but the suggested solution is for MediaPlayer
and not for VideoView
.
那么我该如何检测VideoView是否正在缓冲?运行线程来检查当前的搜索/进度级别,并根据该决定是播放视频还是缓冲视频,是否是一个好的解决方案?
SO how can I detect if VideoView is buffering? is it a good solution to run a thread to check the current seek/progress level and depending on that decide if video is playing or buffering.
更新
这不像我只需要检查视频是否正在播放或仅在视频开始播放时缓冲,我想在整个视频支付过程中检查它.
It is not like i just need to check if video is playing or buffering at the start of the video only, i want to check it through out video paying.
推荐答案
要检查是否正在播放VideoView,可以使用其isPlaying()方法,
To check if VideoView is playing is not you can use its isPlaying() method,
if ( videoView.isPlaying() )
{
// Video is playing
}
else
{
// Video is either stopped or buffering
}
要检查VideoView是否已完成,请使用以下
To check if VideoView is completed use following,
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
// Video Playing is completed
}
});
这篇关于如何检测VideoView是在播放视频还是在缓冲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!