簡體   English   中英

iOS AVPlayer未加載大多數HLS流

[英]iOS AVPlayer not loading most HLS streams

我正在嘗試使用嵌入在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流它不再起作用。 我得到這個圖像: 死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>

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM