Here is a rudimentary playMe function calling AVPlayer
, playing a MP3, MP4 or Wav via Swift with AppleTV. How do I combine this with the AVPlayerViewController
- i.e., how do I make the playMe("video", "mp4") play inside an AVPlayerViewController
, what are the required steps to make a connection between the Main.storyboard and the AVPlayerViewController, in the GUI and in the Swift code?
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()
}