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.
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
}
});
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With