Shibili k.p
Shibili k.p

Reputation: 571

AVPlayer full screen issue only for iPhone x

I created a splash video using Av player view controller. its is coming properly for all the devices except I Phone X. I tried changing video gravity frame and everything but it won't work. any Idea about this? here is the sample code :

guard let videoPath = Bundle.main.path(forResource: "Redtaxi-splash", ofType:"mov") else {
    return
}

let videoURL = URL(fileURLWithPath: videoPath)
let player = AVPlayer(url: videoURL)
playerViewController = AVPlayerViewController()
playerViewController?.player = player
playerViewController?.showsPlaybackControls = false
playerViewController?.view.frame = view.frame
playerViewController?.view.backgroundColor = .white
playerViewController?.view.contentMode = .scaleAspectFill


NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying(note:)),
                                       name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)

view.addSubview((playerViewController?.view)!)
playerViewController?.player?.play()

Upvotes: 2

Views: 3951

Answers (2)

Zoltan Vinkler
Zoltan Vinkler

Reputation: 1283

Swift 4

playerViewController.videoGravity = AVLayerVideoGravity.resizeAspectFill.rawValue

Upvotes: 1

Shibili k.p
Shibili k.p

Reputation: 571

I fixed this by giving the video gravity for the player view controller :

playerViewController.videoGravity = .resizeAspectFill

this will fix the issue by using the video gravity as aspect fill for the avplayer view controller. here is the documentation for video gravity:

The video gravity determines how the video content is scaled or stretched within the player layer’s bounds.

Upvotes: 12

Related Questions