I want to check if swipe gesture working or not on AVPlayer video. I tried a small sample app to do so but it did not work. Not sure why code is not working.
On button tap, below is the code:
var playerLayer: AVPlayerLayer?
var player: AVPlayer?
let videoUrlString = "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
let videoURL = URL(string: videoUrlString)
self.player = AVPlayer(url: videoURL!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true, completion: {
self.player?.play()
})
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:)))
leftSwipe.direction = UISwipeGestureRecognizer.Direction.up
playerViewController.view.addGestureRecognizer(leftSwipe)
@objc func handleSwipes(_ sender:UISwipeGestureRecognizer) {
if (sender.direction == .left) {
let alert = UIAlertController(title: "Swipe Action", message: "It is LEFT Swipe ", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true
}
}
Thanks