开发者

Android Show image while video is buffering?

开发者 https://www.devze.com 2023-01-02 13:30 出处:网络
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.

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 bu开发者_JAVA百科ffering 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号