我有一个应用程序,使用AVPlayer播放AVPlayerItem (视频)从一个远程网址。在iOS 6-8中,我一直在观察loadedTimeRanges的AVPlayerItem's值,以便在playerItem准备好由播放器播放时通知我。我相信,在观察项目的duration值时,这也是有效的。
在更新到iOS 9测试版之后,我在AVPlayerItem上观察到的所有值都无法到达observeValueForKeyPath-method。就好像我根本没在观察他们一样。AVPlayer上的值仍在通知我,而AVPlayerItem上的值没有通知我。这可能是一个bug,还是这里的环境发生了一些变化?我找不到关于这件事的任何东西。
澄清一下,在iOS 6-8中,只要有任何加载的时间范围,视频就开始播放。在iOS9中,当加载了任何时间范围时,都不会通知我。
更新
在观察了AVPlayerItem的值AVPlayerItem之后,我现在已经确认该项的状态已更改为Failed。通过在失败后注销项目的NSError,我得到了以下内容:
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}发布于 2015-07-16 01:30:38
我今天也遇到了同样的问题。在我的例子中,由于iOS 9中新的应用程序传输安全功能,视频加载失败了。
您可以在info.plist中添加一个按域异常,如下所示:
<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>如果您需要从任意域加载视频,则可以完全禁用,尽管不建议这样做。
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>https://stackoverflow.com/questions/30984433
复制相似问题