I'm having the same problem as this question but I don't see where I'm going wrong.
It still remains on the last frame of the video on the external display.
iOS Swift App AVPlayerController dismiss not working on external display
Unfortunately, I don't have enough reputation points to comment on the other question.
Is it because I don't have an AVPlayerItem?
let fourVideoViewController = AVPlayerViewController()
@IBAction func fourVideoPlayButton(_ sender: Any) {
let fourVideoURL = Bundle.main.url(forResource: "Four Animation",
withExtension: "mov")!
let fourPlayer = AVPlayer(url: fourVideoURL as URL)
fourVideoViewController.player = fourPlayer
NotificationCenter.default.addObserver(self, selector:
#selector(playerDidFinishPlaying), name:
NSNotification.Name.AVPlayerItemDidPlayToEndTime, object:
fourVideoViewController.player?.currentItem)
self.present(fourVideoViewController, animated: true) {
self.fourVideoViewController.player!.play()
}
}
@objc func playerDidFinishPlaying(note: NSNotification) {
fourVideoViewController.dismiss(animated: true, completion: nil)
fourVideoViewController.view.removeFromSuperview()
self.presentedViewController?.dismiss(animated: true, completion: nil)
}