在AR应用程序中,当我检测到图像时,将显示几个按钮,其中一个按钮将播放AVPlayerViewController
中的视频。
问题在于播放视频时,如果您不小心点击了屏幕,则会激活另一个按钮。
func playVideo() {
let movieURL = Bundle.main.url(forResource: "Video", withExtension: "mp4")!
let player4 = AVPlayer(url: movieURL as URL)
playerViewController.player = player4
NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerViewController.player?.currentItem)
self.present(playerViewController, animated: true) {
self.playerViewController.player!.play()
}
playerViewController.entersFullScreenWhenPlaybackBegins = true
}
@objc func playerDidFinishPlaying(note: NSNotification) {
self.playerViewController.dismiss(animated: true)
}