本文介绍了在iOS9中观察AVPlayerItem上的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用AVPlayer从远程URL播放AVPlayerItem(视频)的应用程序.在iOS 6-8中,我一直观察AVPlayerItem'sAVPlayerItem's值,以在播放器准备好播放playerItem时通知我.我相信,在观察项目duration的值时,这也适用.

I have an app that uses AVPlayer to play an AVPlayerItem (video) from a remote URL. In iOS 6-8 I have been observing the AVPlayerItem's value for loadedTimeRanges to notify me when the playerItem is ready to be played by the player. This also works when observing the value for the item's duration, I believe.

在更新到iOS 9 beta之后,我观察到的AVPlayerItem上的任何值都没有达到observeValueForKeyPath方法.就像我根本没有观察到它们一样.我仍然收到AVPlayer上的值通知,但没有收到AVPlayerItem上的值.这可能是错误,还是这里的环境发生了变化?我对此一无所获.

After updating to iOS 9 beta, none of the values on AVPlayerItem I observe ever makes it to the observeValueForKeyPath-method. Just as if I'm not observing them at all. I am still being notified by the values on AVPlayer, but not on AVPlayerItem. Could this be a bug, or did something change in the environment here? I can't find anything about this..

为澄清起见,在iOS 6-8中,只要有任何加载的时间范围,视频就会立即开始播放.在iOS9中,当加载任何时间范围时,我永远不会收到通知.

For clarification, in iOS 6-8 the videos are starting to play as soon as there are any loaded time ranges. In iOS9 I am never notified when any time ranges have been loaded.

更新

在观察AVPlayerItem的值status之后,我现在确认该项目的状态已更改为Failed.通过在失败后注销项目的NSError,我得到了:

After observing the value status for AVPlayerItem I have now confirmed that the item's status is changed to Failed. By logging out the item's NSError after failing, I get this:

Error Domain=AVFoundationErrorDomain Code=-11800
    "The operation could not be completed"
    UserInfo=0x146023c90 {NSUnderlyingError=0x144f547d0
    "The operation couldn’t be completed. (OSStatus error -1022.)",
    NSLocalizedFailureReason=An unknown error occurred (-1022),
    NSLocalizedDescription=The operation could not be completed}

推荐答案

我今天遇到了同一问题.就我而言,由于iOS 9中新的App Transport Security功能,视频加载失败.

I ran into the same issue today. In my case, loading the video was failing due to the new App Transport Security feature in iOS 9.

您可以像这样向您的info.plist添加每个域的例外:

You can add a per-domain exception to your info.plist like this:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>

如果您需要从任意域加载视频,则可以完全禁用App Transport Security,尽管不建议这样做.

If you need to load videos from arbitrary domains, you can disable App Transport Security altogether, although this is not recommended.

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

这篇关于在iOS9中观察AVPlayerItem上的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 21:14