2015-11-08 36 views
0

我試圖在我的應用中加載HLS流,但我無法讓它們甚至正確顯示。我有一個AVPlayerViewController設置爲我的應用程序的初始視圖控制器和下面的代碼: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/[email protected]/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瀏覽器完美地工作(儘管你可能需要在德國看到它),所以我不知道爲什麼它不適用於iOS。取而代之的是流的,我的應用程序顯示此:

Screenshot of the running app

這有什麼錯我的代碼?

更新:無論我使用哪個URL,即使使用無效URL,也會發生完全相同的事情。我不知道這裏發生了什麼。

回答

0

原來,因爲我忘記禁用ATS,流沒有加載。難怪所有這些僅限HTTP的流沒有加載。 DERP

(我知道的一個事實,即禁用ATS很少是很好的解決方案,但在這種情況下,我有超過加載的網址完全控制,所以有。)