AVPlayerLayer - 重新编程轮子?

发布于 2024-10-05 00:59:35 字数 710 浏览 4 评论 0原文

我目前正在使用 AVPlayer 和 AVPlayerLayer 来播放一些视频。在播放视频时,我注册了视频期间每 30 秒更新一次的时间。这用于绘制视频中该点的加速度图表,并使其随视频一起更新。该图使用视频中的 CMTime,因此如果我跳到视频的不同部分,该图会立即表示视频中的该时间点,无需额外工作。

任何人,据我所知,如果我想要获得类似于 MediaPlayer 框架提供的界面,我将必须自己做。

我想知道的是,有没有办法将我的 AVPlayer 与 MediaPlayer 框架一起使用? (我看不到。)或者,有没有一种方法可以使用 MediaPlayer 框架注册增量时间更新。

如果有人感兴趣,我的代码如下:

[moviePlayer addPeriodicTimeObserverForInterval: CMTimeMake(1, 30) queue: dispatch_queue_create("eventQueue", NULL) usingBlock: ^(CMTime time) {
 loopCount = (int)(CMTimeGetSeconds(time) * 30);
 if(loopCount < [dataPointArray count]) {
  dispatch_sync(dispatch_get_main_queue(), ^{
   [graphLayer setNeedsDisplay];
  });
 }
}];

谢谢!

I'm currently using an AVPlayer, along with an AVPlayerLayer to play back some video. While playing back the video, I've registered for time updates every 30th of a second during the video. This is used to draw a graph of the acceleration at that point in the video, and have it update along with the video. The graph is using the CMTime from the video, so if I skip to a different portion of the video, the graph immediately represents that point in time in the video with no extra work.

Anywho, as far as I'm aware, if I want to get an interface similar to what the MediaPlayer framework offers, I'm going to have to do that myself.

What I'm wondering is, is there a way to use my AVPlayer with the MediaPlayer framework? (Not that I can see.) Or, is there a way to register for incremental time updates with the MediaPlayer framework.

My code, if anyone is interested, follows :

[moviePlayer addPeriodicTimeObserverForInterval: CMTimeMake(1, 30) queue: dispatch_queue_create("eventQueue", NULL) usingBlock: ^(CMTime time) {
 loopCount = (int)(CMTimeGetSeconds(time) * 30);
 if(loopCount < [dataPointArray count]) {
  dispatch_sync(dispatch_get_main_queue(), ^{
   [graphLayer setNeedsDisplay];
  });
 }
}];

Thanks!

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

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

发布评论

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

评论(3

朮生 2024-10-12 00:59:35

如果您正在谈论 MPMoviePlayer 显示的窗口镶边,那么恐怕您正在考虑自己创建此 UI。

AFAIK 无法使用 MediaPlayer 框架实现您需要的计时行为,它是一个非常简单的“播放一些媒体”框架。使用 AVFoundation 您正在做正确的事情。

这使得您需要自己创建 UI。我的建议是从 XIB 文件开始来创建总体布局;顶部的工具栏有一个完成按钮,一个代表自定义播放视图(使用 AVPlayerLayer)的大视图和一个包含控件的单独视图。

如果您想模拟 MPMoviePlayer UI,您需要编写一些自定义控制器代码来根据需要自动显示/隐藏播放控件和工具栏。

If you're talking about the window chrome displayed by MPMoviePlayer then I'm afraid you are looking at creating this UI yourself.

AFAIK there is no way of achieving the timing behaviour you need using the MediaPlayer framework, which is very much a simple "play some media" framework. You're doing the right thing by using AVFoundation.

Which leaves you needing to create the UI yourself. My suggestion would be to start with a XIB file to create the general layout; toolbar at the top with a done button, a large view that represents a custom playback view (using your AVPlayerLayer) and a separate view to contain your controls.

You'll need to write some custom controller code to automatically show/hide the playback controls and toolbar as needed if you want to simulate the MPMoviePlayer UI.

⊕婉儿 2024-10-12 00:59:35

您可以使用 https://bitbucket.org/brentsimmons/ngmovieplayer 作为起点(如果它存在于你问的时间)。

从项目页面:“复制 MPMoviePlayerViewController 的大部分行为 - 但使用 AVFoundation。”

You can use https://bitbucket.org/brentsimmons/ngmovieplayer as a starting point (if it existed at the time you asked).

From the project page: "Replicates much of the behavior of MPMoviePlayerViewController -- but uses AVFoundation."

悲欢浪云 2024-10-12 00:59:35

您可能需要查找 AVSynchronizedLayer 类。我认为官方编程指南中没有太多内容。您可以在这里或那里找到一些信息: 进一步Otter Software

在 O'Really Programming iOS 4(或 5)中,还有一个简短的参考,介绍如何让正方形沿着一条线与动画同步移动/停止。
WWDC 2011 会议期间展示了另一个演示(代码不多)使用媒体在 AV 基金会

You might want to look for AVSynchronizedLayer class. I don't think there's a lot in the official programming guide. You can find bits of info here and there: subfurther, Otter Software.

In O'Really Programming iOS 4 (or 5) there's also a short reference on how to let a square move/stop along a line in synch with the animation.
Another demo (not a lot of code) is shown during WWDC 2011 session Working with Media in AV Foundation.

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