11

How to detect if VideoView is playing video or Buffering?
I want to display a pop-up saying video is buffering.

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).

I have also seen this question "Detect if a VideoVIew is buffering" but the suggested solution is for MediaPlayer and not for 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.

UPDATE

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.

Community
  • 1
  • 1
User7723337
  • 11,857
  • 27
  • 101
  • 182

3 Answers3

13

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
}

To check if VideoView is completed use following,

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
{
    @Override
    public void onCompletion(MediaPlayer mp) 
    {
             // Video Playing is completed
    }
});
Lucifer
  • 29,392
  • 25
  • 90
  • 143
  • We need to add `videoView.isPlaying()` to a timer to keep checking if video is buffering or we need to set the `setOnBufferingUpdateListener` to check if it is in buffering mode. – User7723337 Dec 05 '14 at 08:47
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);
Attif
  • 1,158
  • 13
  • 17
1
           videoView.setOnPreparedListener(new OnPreparedListener()
           {

               public void onPrepared(MediaPlayer mp)
               {                  
                   progressDialog.dismiss();     // or hide any popup or what ever
                   videoView.start();           // start the video
               }
           });