I have an app that is locked to portrait mode (only "portrait" box checked in Build Settings in Xcode). In a ViewController I have an AVPlayerViewController in a containerView that loads a remote url.
It's my understanding that since WWDC19/iOS 13, AVPlayerController automatically handles landscape viewing, even in apps that are portait-only. This is the case in my app - the AVPlayerController correctly switches to landscape with rotation of the device. Also, if I use the close/"X" button to dismiss the player from full screen in any orientation, it correctly dismisses back to portrait orientation.
The problem is with swipe gestures & swipe to dismiss. If I swipe to dismiss in portrait full screen, it correctly dismisses back to the portrait ViewController. If I swipe to dismiss in landscape full screen however, I get a black screen. The audio continues to play but the app is completely unresponsive with just a black screen.
I also get a black screen if I do a swipe up gesture in any orientation. It seems like the video frame tries to go back to its original place but then just goes black.
I've tried playing with viewWillAppear of ViewController, and tried delegate methods of AVPlayerViewControllerDelegate with no luck.
Here's the code I'm using in my ViewController class:
import UIKit
import AVKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
configureVideoPlayer()
}
private func configureVideoPlayer() {
let playerViewController = AVPlayerViewController()
let url: URL! = URL(string: "https://www.radiantmediaplayer.com/media/bbb-360p.mp4")
let player = AVPlayer(url: url)
playerViewController.player = player
playerViewController.frame = containerView.bounds
containerView.addSubview(playerViewController.view)
addChild(playerViewController)
}