Here's what I have and I want this video to fill the whole screen (aspectFill)
playerLayer.videoGravity = kCAGravityResizeAspectFill is supposed to do the Aspect Fill but I still get black bars at the top and bottom of the screen.
The last line is supposed to loop the video but instead it just dims and stops playing.
Any suggestions are appreciated.
var moviePlayer: AVPlayer!
override func viewDidLoad() {
super.viewDidLoad()
// Load the video from the app bundle.
let videoURL: NSURL = NSBundle.mainBundle().URLForResource("video", withExtension: "mp4")!
self.moviePlayer = AVPlayer(URL: videoURL)
self.moviePlayer.muted = true
let playerLayer = AVPlayerLayer(player: self.moviePlayer)
playerLayer.videoGravity = kCAGravityResizeAspectFill //this not working
playerLayer.zPosition = -1
playerLayer.frame = self.view.frame
self.view.layer.addSublayer(playerLayer)
self.moviePlayer.play()
// Loop video.
NSNotificationCenter.defaultCenter().addObserver(self, selector: "loopVideo", name: AVPlayerItemDidPlayToEndTimeNotification, object: self.moviePlayer)
}
func loopVideo() {
self.moviePlayer.play()
}