播放视频时,可以按下AVPlayerViewController中正在播放的视频后面的按钮

时间:2019-06-03 09:44:56

标签: ios swift xcode

在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)
}

0 个答案:

没有答案