I am trying to popup a snack bar during a random time when the video plays I already got the video duration plus able to run the video. I have also able to set up the handler to show the snack bar at random time during the video duration.
Uri uri2 = Uri.parse("my video link");
MediaPlayer mp = MediaPlayer.create(this, uri2);
int duration = mp.getDuration();
mp.reset();
mp.release();
mVideoView2.setVideoURI(uri2);
mVideoView2.requestFocus();
mVideoView2.start();
I have only one problem. When I call videoview.start() it doesn't start the video immediately, it has some buffer time. I only want to show up the snackbar at random time during the video play. Assume the video length is 7 sec and my random time is 3 sec, and buffer time or preloading time is like 3 sec, the snackbar shows up before my video. Is there some way to know the buffer time or when the video is ready so that I can start calling my handler.
Set a OnPreparedListener
to get notified when video loads
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
//play video... video is ready to play
}
});