這是一個基本的playMe函數,調用AVPlayer
,通過AppleTV與Swift一起播放MP3,MP4或Wav。我該如何將它與AVPlayerViewController
結合 - 也就是說,如何讓playMe(「video」,「mp4」)在AVPlayerViewController
內播放,在Main.storyboard和AVPlayerViewController之間建立連接所需的步驟是什麼GUI和Swift代碼中?你可以這樣做Swift/AppleTV4:如何將AVPlayer功能連接到AVPlayerViewController?
func playMe(inputfile: String, inputtype: String) {
let path = NSBundle.mainBundle().pathForResource(inputfile, ofType:inputtype)!
let videoURL = NSURL(fileURLWithPath: path)
let player = AVPlayer(URL: videoURL)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()
}
我不熟悉tvOS但谷歌搜索「[tvos視頻播放控件(https://www.google.com/webhp?sourceid = chrome-instant&ion = 1&espv = 2&ie = UTF-8#q = tvos%20video%20playback%20controls)「顯示[Apple說](https://developer.apple.com/library/tvos/documentation /AVFoundation/Reference/AVPlayerViewController_Class/index.html)'AVPlayerViewController''「顯示AVPlayer對象的視頻內容以及系統提供的播放控件。」所以我認爲你必須朝着這個方向努力...至少在'蘋果之路'中 –