'How to make custom video player with swift

I'm trying to make a video player like youtube, with double-tap the screen to fast forward 5 seconds. But I'm having trouble implementing that. I tried using code below:

class VideoViewController: AVPlayerViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    let doubleTap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
    doubleTap.numberOfTapsRequired = 2
    doubleTap.delegate = self

    self.view.addGestureRecognizer(doubleTap)
    // Do any additional setup after loading the view.
}


extension VideoViewController: UIGestureRecognizerDelegate {
    @objc func handleTap(_ gesture: UITapGestureRecognizer){
        print("doubletapped")
    }
}

This is how I call it:

let player = AVPlayer(url: self.fileURLs[indexPath.row])
        let playerController = VideoViewController()

        playerController.player = player
        self.present(playerController, animated: true) {
            playerController.player!.play()
        }

But still Swift cannot recognize the double tap when playing video. I try to disable userinteractoin but still no luck. Anyone please give me some hints. Thanks!!



Solution 1:[1]

Make user interaction enable View.isUserInteractionEnable =true

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mayank Kushwaha