我正试图在我的应用程序中加载HLS流,但我无法让它们正确显示。我将一个AVPlayerViewController设置为我的应用程序的初始视图控制器,并编写了以下代码:
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()
}在桌面Safari中打开该URL工作得非常完美(尽管您可能必须在德国才能看到它),所以我不知道为什么它不能在iOS上工作。而不是流,我的应用程序显示如下:
运行应用程序的屏幕截图
我的密码怎么了?
更新:完全相同的事情发生,无论我使用什么网址,即使是无效的。我不知道这里发生了什么。
发布于 2015-11-08 21:45:10
结果是流没有装载因为我忘了禁用ATS。难怪所有那些HTTP专用的流都没有加载。德普
(我知道禁用ATS很少是一个好的解决方案,但在这种情况下,我可以完全控制加载的URL,所以就有了。)
https://stackoverflow.com/questions/33597047
复制相似问题