Android 在视频缓冲时显示图像?

发布于 2024-09-04 20:28:21 字数 438 浏览 2 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断舍离 2024-09-11 20:28:21

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文