Chris
Chris

Reputation: 545

Android Show image while video is buffering?

I have an app that displays a video using VideoView. The layout consists of a Clock and a VideoView laid out in a simple vertical LinearLayout.

Here's my code snippet that I use:

VideoView mVideoView = new VideoView(this);
mVideoView.setVideoPath(myVideoURL);
mVideoView.requestFocus();
mVideoView.start();

Since the buffering of the video takes about 8-10 seconds, the layout comes up with the Clock, but the VideoView stays blank. What I want to achieve is this:

-- Display an ImageView for the 10s while the video is buffering -- Detect when the video is ready to be played (onPrepared?) -- Show the Clock and VideoView and start the Video

Anyone have pointers on how to go about this?

Thanks Chris

Upvotes: 1

Views: 4332

Answers (1)

JRL
JRL

Reputation: 78033

MediaPlayer will let you register an OnPreparedListener callback which you can use to determine when the video is ready to be started. So you would show your ImageView instead of your VideoView first, then when your callback gets called, change to the VideoView and start playing.

Upvotes: 2

Related Questions