make AVPlayer fill the entire screen

Define the playerLayer.frame inside viewDidLayoutSubviews()

At the time you are defining the frames the final frames for the views were not yet calculated.


If you want to video to be stretch on the entire view, just delete the line

playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill

videoGravity default value is AVLayerVideoGravityResize

Update for Swift 5

playerLayer.videoGravity = .resizeAspectFill