AVPlayer和MPMoviePlayerController的区别 [英] AVPlayer and MPMoviePlayerController differences

查看:221
本文介绍了AVPlayer和MPMoviePlayerController的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款需要播放视频的iPhone应用程序。
到目前为止,我了解到至少有两个API用于实现这一目标; AVPlayer MPMoviePlayerController

I am developing an iPhone application that needs to play videos. So far, I learned that there are at least two API's for achieving this; AVPlayer and MPMoviePlayerController.

主要区别是什么?

推荐答案

注意从iOS9开始,Apple已弃用MPMoviePlayerController:

NOTE as of iOS9, Apple has deprecated the MPMoviePlayerController:


MPMoviePlayerController类在iOS 9中正式弃用。(MPMoviePlayerViewController类也正式弃用。)要在iOS 9及更高版本中播放视频内容,请使用AVPictureInPictureController或来自AVKit框架的AVPlayerViewController类,或来自WebKit的WKWebView类。

The MPMoviePlayerController class is formally deprecated in iOS 9. (The MPMoviePlayerViewController class is also formally deprecated.) To play video content in iOS 9 and later, instead use the AVPictureInPictureController or AVPlayerViewController class from the AVKit framework, or the WKWebView class from WebKit.

MPMoviePlayerController reference

AVPlayer

AVPlayer 为您提供了更多的灵活性,但记录很差。使用此API将强制您创建自己的UI。 AVFoundation (带给你 AVPlayer 的框架)通常对用户(编码器)有点困难,因为它强迫你使用键值观察来检查状态。 KVO的概念很棒,不要误会我的意思 - 对于没有经验的开发人员来说,学习它会很痛苦。 Apple有时会忽略哪些属性实际符合KVO的信息,这将迫使您进行一些实验。

AVPlayer gives you a lot more flexibility but is pretty poorly documented. Using this API will force you to create your own UI. AVFoundation (the framework that brings you AVPlayer) generally is a bit hard on the user (coder) as it forces you to use Key-Value Observing a lot for checking states. The concept of KVO is great, do not get me wrong - still, for unexperienced developers it can be painful to learn. Apple sometimes omits the information on which properties are actually KVO compliant and that will force you to do some experimentation.

AVPlayer的一大优势 over MPMoviePlayerController 例如是它的扩展版本, AVQueuePlayer 因为它可以做无间隙播放多个电影源。
另一个优势当然是功能丰富的 AVFoundation 框架,允许您进行动态电影合成/编码/转换等操作。

One big advantage of AVPlayer over MPMoviePlayerController would for example be its extended version, AVQueuePlayer as that one is able to do gapless playback of multiple movie sources. Another advantage certainly is the feature rich AVFoundation framework allowing you to do things like on-the-fly movie composition / encoding / converting.

AVPlayer 的另一个巨大优势是你实际上可以同时播放多个视频源(例如,旁边的)没有任何问题。

Yet another huge advantage of AVPlayer is the fact that you may actually play multiple video sources concurrently (e.g. side by side) without any problem.

MPMoviePlayerController

MPMoviePlayerController 很容易使用和涵盖大多数开箱即用的需求。使用此API将为您提供美观且易于理解的UI。但是,UI可以被禁用,也可以用自定义替换。

MPMoviePlayerController is easy to use and covers most needs out of the box. Using this API will give you a good looking and commonly understood UI. The UI however can be disabled and or replaced with a custom one.

对于状态更改, MPMoviePlayerController 使用一些 NSNotifications 涵盖常规应用程序所需的所有内容。

For status changes, MPMoviePlayerController uses a few NSNotifications covering everything the regular App needs.

引擎盖下, MPMoviePlayerController 构建在 AVPlayer 之上 - 但这实际上对用户完全透明 - 使用 MPMoviePlayerController时无法访问该层/ code>。

Under the hood, MPMoviePlayerController builds on top of AVPlayer - but that actually happens entirely transparent to the user - you have no access to that layer while using MPMoviePlayerController.

MPMoviePlayerController 使用底层 AVPlayer 作为单例实例,因此不可能使用 MPMoviePlayerController 的多个实例同时播放视频。

MPMoviePlayerController uses the underlaying AVPlayer as a singleton instance, hence it is not possible to use multiple instances of MPMoviePlayerController to play videos concurrently.

另一方面,只要您尝试使用自己的功能扩展 MPMoviePlayerController 的功能,代码就会很快变得令人讨厌 - 例如您可能会开始使用多个计时器来覆盖诸如正确的饥饿检测之类的东西(实际上,该功能已包含在iOS5的此类版本中),自定义UI更新,...或者您最终可能拥有多个州尝试覆盖播放器仍处于预缓冲状态时优雅中止播放的属性。

On the other hand, as soon as you are trying to extend the functionality of MPMoviePlayerController with your own features, code quickly gets nasty - e.g. you will possibly start using multiple timers for covering things like a proper starve-detection (actually, that feature got included into iOS5's version of this class), custom UI updates, ... Or you may end up having more than a handful of state properties trying to cover things like gracefully aborting of the playback while the player is still pre-buffering.

个人推荐

Personal Recommendation

我已经使用了两者,我会继续使用两者,根据应用程序的需要,我很高兴建立。
对于大多数(简单)项目,我建议在 AVPlayer 上使用 MPMoviePlayerController ,因为它非常简单使用,只需几行代码,您就可以获得成熟的媒体播放器。如果您对媒体播放的要求更加简单,请查看 MPMoviePlayerViewController (请注意View-part)。

I have used both and I will continue to use both, depending on the needs of the App I have the pleasure to build. For most (simple) projects, I would recommend using MPMoviePlayerController over AVPlayer as it is very simple to use and with just a few lines of code, you get a full-fledged media player. And if your demands on media playback are even simpler, have a peek at MPMoviePlayerViewController (note that View-part).

这篇关于AVPlayer和MPMoviePlayerController的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆