2015-09-25 66 views
2

我想在Apple TV上打開我的應用時播放一段視頻(20秒)。但我無法找到如何從本地文件實現URL。使用tvOS從本地文件播放視頻

這是我這麼遠,但遺憾的是它不工作:

override func viewDidLoad() { 
     super.viewDidLoad() 

     // I know this is how to play a file from a webserver: 
     // player = AVPlayer(URL: NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!) 

     // But I can't find how to set the URL to a local file in the app 
     let path = NSBundle.mainBundle().pathForResource("bunny", ofType:"mp4") 
     let url = NSURL.fileURLWithPath(path!) 
     player = AVPlayer(URL: url) 

     player?.play() 

    } 

回答

1

您的代碼似乎罰款。也許,你應該試試這個:

在Project Navigator中選擇你的項目根目錄>你的目標> Build Phases> Copy Bundle Resources。請檢查您的視頻是否在 ,如果沒有點擊加號來添加它。

來源:http://www.brianjcoleman.com/tutorial-play-video-swift/