Done button click event in AVPlayerViewController

前端 未结 9 865
广开言路
广开言路 2020-12-03 17:40

I want to play local video in AVPlayerViewController but did not find click event of Done button.

My video is able to play in AVPlayerViewController but I did not fi

9条回答
  •  悲&欢浪女
    2020-12-03 17:48

    I found a workaround without having to subclass the AVPlayerViewController, which the documentation clearly states you should not (https://developer.apple.com/documentation/avkit/avplayerviewcontroller). It is not pretty, but it got the job done for me by giving me somewhere to run code when the AVPlayerViewController is dismissed.

    AnyViewController: UIViewController, AVPlayerViewControllerDelegate {
        private let playerVC = AVPlayerViewController()
    
        override func viewDidLoad() {
            playerVC.delegate = self        
        }
    
        func playerViewController(_ playerViewController: AVPlayerViewController, willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
            if playerViewController.isBeingDismissed {
                playerViewController.dismiss(animated: false) { [weak self] in
                    self?.someDismissFunc()
                }
            }
        }
    }
    

    It is really messed up that there is no clean way of doing this as far as I can tell :(

提交回复
热议问题