8
votes

I am trying to stream HLS video using an AVPlayer embedded in an AVPlayerViewController. 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

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. I get this image: dead AVPlayer

I can open the stream using safari and it works fine. I have also validated the stream using the Apple's HTTP Live Streaming Tools

I am a bit stuck now. Any ideas?

1
have you tried submitting a bug report to Apple for this?Yuchen
I am having the same problem and this solution helps me, stackoverflow.com/a/53020960/9049312Fariha Hasan

1 Answers

0
votes

I was using HTTP URL which is not secured thus, it doesn't allow device or simulator to play it. I put an exception in info.plist to allow insecure protocols which let the iOS to stream the HLS smoothly.

 <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <true/>
        <key>NSExceptionAllowsInsecureHTTPLoads</key>
        <true/>
        <key>NSIncludesSubdomains</key>
        <true/>
    </dict>

enter image description here