[英]iOS AVPlayer not loading most HLS streams
I am trying to stream HLS video using an AVPlayer embedded in an AVPlayerViewController. 我正在尝试使用嵌入在AVPlayerViewController中的AVPlayer来传输HLS视频。 To do this I am doing the following to setup an AVPlayerViewController, following the apple docs here: https://developer.apple.com/library/mac/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html 要做到这一点,我正在做以下设置AVPlayerViewController,遵循苹果文档: https : //developer.apple.com/library/mac/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html
let url = NSURL.init(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8") // example URL from apple dev works!
let asset = AVURLAsset.init(URL: url!)
let requestedKeys = ["tracks"]
asset.loadValuesAsynchronouslyForKeys(requestedKeys) {
() -> Void in
dispatch_async(dispatch_get_main_queue())
{
let error = NSErrorPointer()
let status = asset.statusOfValueForKey("tracks", error: error)
if (status == AVKeyValueStatus.Loaded) {
let playerItem = AVPlayerItem.init(asset: asset)
playerItem.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.init(rawValue: 0), context: nil)
self.avPlayerViewController.player = AVPlayer.init(playerItem: playerItem)
}
else {
// You should deal with the error appropriately.
NSLog("The asset's tracks were not loaded:\n%@", (error.memory)!.localizedDescription);
}
}
}
this all works fine. 一切正常。 But when I change the url to 但是当我改变网址时
let url = NSURL.init(string: "http://cdn-fms.rbs.com.br/hls-vod/sample1_1500kbps.f4v.m3u8") // but this one doesn't
or any other HLS stream it doesn't work anymore. 或任何其他HLS流它不再起作用。 I get this image: dead AVPlayer 我得到这个图像: 死AVPlayer
I can open the stream using safari and it works fine. 我可以使用safari打开流,它工作正常。 I have also validated the stream using the Apple's HTTP Live Streaming Tools 我还使用Apple的HTTP Live Streaming Tools验证了流
I am a bit stuck now. 我现在有点卡住了。 Any ideas? 有任何想法吗?
I was using HTTP URL which is not secured thus, it doesn't allow device or simulator to play it. 我使用的HTTP URL因此不受保护,它不允许设备或模拟器播放它。 I put an exception in info.plist to allow insecure protocols which let the iOS to stream the HLS smoothly. 我在info.plist中添加了一个异常,允许不安全的协议让iOS顺利地流式传输HLS。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.