Android 在视频缓冲时显示图像?
我有一个使用 VideoView 显示视频的应用程序。该布局由放置在简单垂直 LinearLayout 中的 Clock 和 VideoView 组成。
这是我使用的代码片段:
VideoView mVideoView = new VideoView(this);
mVideoView.setVideoPath(myVideoURL);
mVideoView.requestFocus();
mVideoView.start();
由于视频缓冲大约需要 8-10 秒,因此布局出现了时钟,但 VideoView 保持空白。我想要实现的是:
-- 在视频缓冲时显示 ImageView 10 秒 -- 检测视频何时准备好播放(onPrepared?) -- 显示时钟和视频视图并启动视频
有人知道如何进行此操作吗?
谢谢 克里斯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MediaPlayer 将允许您注册一个可以使用的 OnPreparedListener 回调确定视频何时准备好开始。因此,您将首先显示 ImageView 而不是 VideoView,然后当您的回调被调用时,更改为 VideoView 并开始播放。
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.