11

如何检测 VideoView 是在播放视频还是在缓冲?
我想显示一个弹出窗口,说视频正在缓冲。

在 android API 级别 17 中有一个回调setOnInfoListener可以为我提供此信息,但我使用的是 API 级别 15(android ICS)。

我也看过这个问题“检测 VideoVIew 是否正在缓冲”,但建议的解决方案是针对MediaPlayer而不是针对VideoView.

那么如何检测 VideoView 是否正在缓冲?运行一个线程来检查当前的搜索/进度级别并根据它决定视频是正在播放还是正在缓冲是一个很好的解决方案。

更新

这不像我只需要在视频开始时检查视频是否正在播放或缓冲,我想通过视频支付来检查它。

4

3 回答 3

13

要检查 VideoView 是否正在播放,您可以使用它的 isPlaying() 方法,

if ( videoView.isPlaying() )
{
     // Video is playing
}
else
{
     // Video is either stopped or buffering
}

要检查 VideoView 是否已完成,请使用以下命令,

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
{
    @Override
    public void onCompletion(MediaPlayer mp) 
    {
             // Video Playing is completed
    }
});
于 2013-04-11T06:35:53.407 回答
2

I came with the following hack in order to not implement a custom VideoView. The idea is to check every 1 second if the current position is the same as 1 second before. If it is, the video is buffering. If not, the video is really playing.

final Handler handler = new Handler(); 
Runnable runnable = new Runnable() { 
    public void run() {
        int duration = videoView.getCurrentPosition();
        if (old_duration == duration && videoView.isPlaying()) {
            videoMessage.setVisibility(View.VISIBLE);
        } else {
            videoMessage.setVisibility(View.GONE);
        }
        old_duration = duration;

        handler.postDelayed(runnable, 1000);
    }
};
handler.postDelayed(runnable, 0);
于 2016-03-09T15:57:09.953 回答
1
           videoView.setOnPreparedListener(new OnPreparedListener()
           {

               public void onPrepared(MediaPlayer mp)
               {                  
                   progressDialog.dismiss();     // or hide any popup or what ever
                   videoView.start();           // start the video
               }
           });  
于 2013-04-11T06:28:04.180 回答