是否可以通过 HTML5 或 Native App 在 iPad 上同时播放多个视频文件?

发布于 2024-11-14 01:31:17 字数 2001 浏览 9 评论 0原文

无论是在 HTML5 中还是在 Objective-c 中原生编写,我都需要生成一个视频缩略图网格,当页面或视图在 iPad 上加载时,这些缩略图会自动播放。我一直在多个论坛和 StackOverflow 上阅读。有些人表示这可以通过 AVController 实现。包括苹果在内的其他公司表示,

“注意:虽然您可以创建多个 MPMoviePlayerController 对象并在界面中呈现它们的视图,但一次只能有一个电影播放器​​可以播放其电影。”

参考: MPMoviePlayerController

在 HTML5 中,它可以在 Macbook 上运行,所有 9 个视频都在播放:

<video class="movie" src="videos/aerials.m4v" autoplay controls width="200" height="110"></video>

用正确的链接粘贴这个 9x,一个漂亮的视频网格就可以开始播放,没有问题。然而,在 iPad 上,加载到 Web 视图中的 HTML5 会产生相同的 9 网格,但不会立即播放视频。一次只能播放 1 个视频。

现在,我采用了 Objective-C 路径,并尝试使用不同的方法来测试前面引用的 Apple 声明:

moviePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:videoURL];

moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110);
[self.view addSubview:moviePlayer1.view];
[[NSNotificationCenter defaultCenter]addObserver:self 
                                        selector:@selector(movieFinishedCallback:)
                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                          object:moviePlayer1];
[moviePlayer1 play];

moviePlayer2 = [[MPMoviePlayerController alloc]
                initWithContentURL:videoURL];

moviePlayer2.view.frame = CGRectMake(0, 300, 200, 110);
[self.view addSubview:moviePlayer2.view];
[[NSNotificationCenter defaultCenter]addObserver:self 
                                        selector:@selector(movieFinishedCallback:)
                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                          object:moviePlayer2];
[moviePlayer2 play];

这确实在视图上显示了两个视频文件,但同样存在与 HTML5 相同的问题,并且一次只能播放 1 个视频。

我相信这是因为苹果在 iPad 上强制执行解码的硬件限制,以防止 CPU 使用率飙升,并保持对框架中媒体部分的另一个严格控制级别。我是对还是错?如果错误,请帮助提供启用我的任务的代码段。谢谢!

In either HTML5 or written natively in Objective-c, I need to generate a grid of video thumbnails that are automatically playing when the page or view loads on an iPad. I have been reading on multiple forums and StackOverflow. Some people indicate this is possible with AVController. Others including Apple state,

"Note: Although you can create multiple MPMoviePlayerController objects and present their views in your interface, only one movie player at a time can play its movie."

Reference: MPMoviePlayerController

In HTML5, it works on a Macbook where all 9 videos are playing:

<video class="movie" src="videos/aerials.m4v" autoplay controls width="200" height="110"></video>

Paste this 9x with the proper links and a nice grid of videos starts playing no problem. On the iPad however, the HTML5 loaded into a webview yields the same 9 grid but with no videos playing immediately. Only 1 video is playable at a time.

Now I took the objective-c path and tried it with a different approach to test out Apple's statement referenced earlier:

moviePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:videoURL];

moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110);
[self.view addSubview:moviePlayer1.view];
[[NSNotificationCenter defaultCenter]addObserver:self 
                                        selector:@selector(movieFinishedCallback:)
                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                          object:moviePlayer1];
[moviePlayer1 play];

moviePlayer2 = [[MPMoviePlayerController alloc]
                initWithContentURL:videoURL];

moviePlayer2.view.frame = CGRectMake(0, 300, 200, 110);
[self.view addSubview:moviePlayer2.view];
[[NSNotificationCenter defaultCenter]addObserver:self 
                                        selector:@selector(movieFinishedCallback:)
                                            name:MPMoviePlayerPlaybackDidFinishNotification
                                          object:moviePlayer2];
[moviePlayer2 play];

This indeed does show both video files on a view but again the same issue as with HTML5 and only 1 video playable at a time.

I believe this is because of a hardware limitation with decoding potentially that Apple is enforcing on the iPad to prevent CPU usage from sky rocketing and maintaining yet another strict level of control over the media portion in the framework. Am I right or wrong? If wrong, please help provide the code segment that will enable my task. Thanks!

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

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

发布评论

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

评论(1

青巷忧颜 2024-11-21 01:31:17

您实际上已经通过给定的引用回答了您自己的问题。但只是为了让大家清楚,再次从我对 非常相似的问题

那是不可能的。使用 MPMoviePlayerController / MPMoviePlayerViewController 时,一次只能播放一部影片/流。

来自 MPMoviePlayerController 类参考

< em>注意:虽然您可以创建多个 MPMoviePlayerController 对象并在界面中呈现它们的视图,但一次只能有一个电影播放器​​可以播放其电影。

You actually answered your own question already by the given quote. But just to make it clear to everyone, once again from my answer to a very similar question.

That is not possible. Only one movie/stream can be played at a time when using MPMoviePlayerController / MPMoviePlayerViewController.

From MPMoviePlayerController Class Reference

Note: Although you may create multiple MPMoviePlayerController objects and present their views in your interface, only one movie player at a time may play its movie.

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