I am using Swift 3 and I want to add swipe gesture to AVPlayer
. Somebody told me that in order to do this I have to use another view and bring that view to the
Swift 4
You can do it without sView, just add a gesture recognizer to AVPlayerViewController's view:
func playVideo() {
let playerController = AVPlayerViewController()
playerController.player = AVPlayer(url: URL(fileURLWithPath: videoPath))
playerController.showsPlaybackControls = false
playerController.view.isUserInteractionEnabled = true
let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeUp.direction = UISwipeGestureRecognizerDirection.up
playerController.view.addGestureRecognizer(swipeUp)
present(playerController, animated: false) {
playerController.player?.play()
}
}
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
print("swipe up")
}