I'm trying to load HLS streams in my app but I can't get them to even display properly. I have an AVPlayerViewController set up as the initial view controller of my app and the following code:
import UIKit
import AVKit
import AVFoundation
private var playerContext = 0
class PlayerViewController: AVPlayerViewController {
override func awakeFromNib() {
print("awake!")
let URL = NSURL(string: "http://live-lh.daserste.de/i/daserste_de@91204/index_2692_av-b.m3u8")!
let player = AVPlayer(URL: URL)
// player.addObserver(self, forKeyPath: "status", options: [.Old, .New], context: &playerContext) // commented out for testing purposes, doesn't make any difference
self.player = player
self.showsPlaybackControls = true
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if context == &playerContext {
print("\(keyPath!): \(change!)")
} else {
super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context)
}
}
// viewDidLoad() and didReceiveMemoryWarning()
}
Opening that URL in desktop Safari works perfectly (though you might have to be in Germany to see it), so I have no idea why it doesn't work on iOS. Instead of the stream, my app displays this:
What's wrong with my code?
Update: The exact same thing happens no matter what URL I use, even with invalid ones. I have no idea what's going on here.
Turns out that the streams didn't load because I forgot to disable ATS. No wonder all those HTTP-only streams didn't load. derp
(I'm aware of the fact that disabling ATS is rarely a good solution, but in this case I have full control over the URLs loaded, so there.)