这是一个基本的 playMe 函数调用AVPlayer
,通过 Swift 和 AppleTV 播放 MP3、MP4 或 Wav。我如何将它与AVPlayerViewController
- 即,如何让 playMe("video", "mp4") 在一个内部播放AVPlayerViewController
,在 GUI 中建立 Main.storyboard 和 AVPlayerViewController 之间的连接所需的步骤是什么在 Swift 代码中?
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()
}