在一个视频正在缓冲时播放另一个视频

发布于 2024-12-05 10:12:05 字数 459 浏览 1 评论 0原文

我有两个视频。视频 A 存在于设备上,而视频 B 需要从互联网上流式传输。我的目标是在视频 B 开始缓冲时播放视频 A。据我了解,我需要为每个视频创建一个 MediaPlayer 实例。然后我可以在两者上调用prepareAsync()并开始在onPrepared()中播放。然而,Android 中似乎存在一些限制,这些限制共同阻止了其正常工作:

1) MediaPlayer 仅在提供了屏幕上存在的 SurfaceView 后才能开始缓冲。

2) 一次只能有一个MediaPlayer连接到SurfaceView。

3) 屏幕上仅支持单个SurfaceView。

我已经成功地通过一部手机获得了两个 MediaPlayer 实例来共享一个 SurfaceView。另一方面,我可以同时在屏幕上显示两个 SurfaceView。但据我了解,Android 官方均不支持?

我做错了什么吗?还有其他人可以做到这一点吗?

I have two videos. Video A is present on the device while video B needs to be streamed off the internet. My goal is to play video A while video B starts buffering. As I understand it I need to create one MediaPlayer instance for each video. Then I can call prepareAsync() on both and start playing in onPrepared(). However, there seem to be some limitations in Android which together prevent this from working properly:

1) MediaPlayer can only start buffering after it has been provided a SurfaceView which is present on screen.

2) Only one MediaPlayer at a time can be connected to a SurfaceView.

3) There is only support for a single SurfaceView on screen.

One one phone I have managed to get two MediaPlayer instances to share one SurfaceView. On another I can get two SurfaceViews on screen at the same time. But as I understand it neither is officially supported by Android?

Am I doing something wrong? Has anyone else got this working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文