We are using AVPlayerViewController to display/play video. Till iOS 15 video player options are visible but for iOS 16 it's not visible.
Do we require to make changes for iOS 16 to display video player options?
Hello!
When you are embedding a view controller in a view hierarchy, it is important to make explicit calls to beginAppearanceTransition
. From the docs:
If you are implementing a custom container controller, use this method to tell the child that its views are about to appear or disappear. Do not invoke viewWillAppear(:), viewWillDisappear(:), viewDidAppear(:), or viewDidDisappear(:) directly.
So, without these calls, those lifecycle methods are not called. In iOS 16, AVPlayerViewController moved its controls view setup into one of those "appear" lifecycle methods. Clients that were embedding AVPlayerViewController without making explicit calls to beginAppearanceTransition "lost" their controls.
Here is an example SwiftUI representable container that demonstrates how to implement this:
struct MyVideoPlayer: UIViewControllerRepresentable {
let player: AVPlayer
func makeUIViewController(context: Context) -> AVPlayerViewController {
let controller = AVPlayerViewController()
controller.player = player
controller.beginAppearanceTransition(true, animated: false)
return controller
}
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {}
static func dismantleUIViewController(_ uiViewController: AVPlayerViewController, coordinator: ()) {
uiViewController.beginAppearanceTransition(false, animated: false)
}
}