我遇到了与该问题相同的问题,但是我看不到哪里出了问题。
它仍然保留在外接显示器上视频的最后一帧中。
iOS Swift App AVPlayerController dismiss not working on external display
不幸的是,我没有足够的声誉分数才能评论另一个问题。
是因为没有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)
}
答案 0 :(得分:0)
您可以尝试在playerDidFinishPlaying
函数中关闭
self.navigationController?.popToRootViewController(animated: true)
OR
self.view.window!.rootViewController?.dismiss(animated: true, completion: nil)
答案 1 :(得分:0)
尝试一下
fourVideoViewController.removeFromParentViewController()
fourVideoViewController.view.removeFromSuperview()
self.presentedViewController?.dismiss(animated: true, completion: nil)