AVPlayerViewController Swipe UISwipeGestureRecognizer.up not working Xcode 12 tvOS 14

410 Views Asked by At

We have just updated Xcode to version 12 and, among others, we have found an issue with setting up a UISwipeGestureRecognizer.up to an AVPlayerViewController. We use that gesture for showing a custom channel changer view. The main issue that it was working on Xcode 11.7 and tvOS 13.

Furthermore, I have debugged the gestureRecognisers for AVPlayerViewController.view and there is no UISwipeGestureRecognizer.

Here is the code I am using

import UIKit
import AVKit

class ViewController: UIViewController {

    private var playerViewController: AVPlayerViewController? {
        didSet {
            guard let playerViewController = playerViewController else {
                return
            }
            
            playerViewController.view.isUserInteractionEnabled = true
            
            let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(testGestureResponse))
            //swipeGesture.direction = .up // Not working
            //swipeGesture.direction = .left
            //swipeGesture.direction = .down
            swipeGesture.direction = .right
            
            playerViewController.view.addGestureRecognizer(swipeGesture)
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        playerViewController = AVPlayerViewController()
        let playerViewController = self.playerViewController!
        
        playerViewController.willMove(toParent: self)
        view.addSubview(playerViewController.view)
        playerViewController.view.frame = view.frame
        addChild(playerViewController)
        playerViewController.didMove(toParent: self)
        
        playerViewController.player = AVPlayer(url: URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_adv_example_hevc/master.m3u8")!)
        playerViewController.player?.play()
    }

    
    @objc func testGestureResponse(gesture: UIGestureRecognizer) {
        print("Hello!!!")
    }

}

Is there a different way to do it now?

1

There are 1 best solutions below

0
On BEST ANSWER

AVPlayerViewController.CustomOverlayViewController was introduced in tvOS 13 and apparently mandatory from tvOS 14. If you want to add a channel charger (or any other view) when swiping up then:

private var playerViewController: AVPlayerViewController? {
    didSet {
        guard let playerViewController = playerViewController else {
            return
        }
        playerViewController.customOverlayViewController = myChannelChangerVC
    }
}

Resources