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
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 :(