AVPlayerViewController deallocated when entering full screen

On iPadOS 13 the AVPlayerViewController throws the following console message when tapping on the expand button in the AVPlayer control:

Warning: <AVPlayerViewController: ...> was deallocated while its contents were being presented full screen. ***

The VC is added by addChildViewController to its parent controller and everything else worked fine when it was built with the iOS 9 SDK. But now with the iPadOS SDK 13 it no longer works.


As a current workarround I set showsPlaybackControls to NO and implemented the expand and collapse feature manually (which works). But I loose all the other features from the playback controls.


Would be great if some can point me in the right solution direction.


Many thanks...

Replies

Hey! I know, little late, but maybe it could help somebody who has this problem too, because i haven't found solution in the whole internet. So this is the line that solved my "deallocated" problem:

controller.modalPresentationStyle = UIModalPresentationStyle.overFullScreen

And this is the full videoplayer struct:

struct CustomVideoPlayer: UIViewControllerRepresentable {

    var url:String

    func makeUIViewController(context: Context) -> AVPlayerViewController {

        let controller = AVPlayerViewController()
        let url: String = url
        let player1 = AVPlayer(url: URL(string: url)!)

        player1.preventsDisplaySleepDuringVideoPlayback = true
        player1.allowsExternalPlayback = true

        //THIS ALLOWS TO USE IT FULLSCREEN %%%%%%% NO BUG MTHERFKER!
        controller.modalPresentationStyle = UIModalPresentationStyle.overFullScreen

        controller.videoGravity = .resizeAspectFill
        controller.player = player1

        return controller

    }

    func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {

    }

}
  • OMG! You totally saved my day. After 8+ hours of googling I finally found the solution to a similar bug!

Add a Comment