微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

iOS AVPlayer未加载大多数HLS流

我正在尝试使用嵌入在AVPlayerViewController中的AVPlayer来传输HLS视频.要做到这一点,我正在做以下设置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);
            }
        }
    }

一切正常.但是当我改变网址时

let url = NSURL.init(string: "http://cdn-fms.rbs.com.br/hls-vod/sample1_1500kbps.f4v.m3u8") // but this one doesn't

或任何其他HLS流它不再起作用.我得到这个图像:
dead AVPlayer

我可以使用safari打开流,它工作正常.我还使用Apple的HTTP Live Streaming Tools验证了流

我现在有点卡住了.有任何想法吗?

解决方法

我使用的HTTP URL因此不受保护,它不允许设备或模拟器播放它.我在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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐