我正在尝试在tvOS中捕获AVPlayervIewController本机播放控件的播放/暂停事件。我试着添加UITapgestureRecogniser,按事件,但都不起作用。现在我正在尝试接收遥控器事件,但也不起作用。
我有MyPlayerViewController: UIViewController,里面有AVPlayerViewController
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.becomeFirstResponder()
UIApplication.shared.beginReceivingRemoteControlEvents()
}
override func remoteControlReceived(with event: UIEvent?) {
if let event = event, event.type == UIEvent.EventType.remoteControl {
if event.subtype == UIEvent.EventSubtype.remoteControlPlay {
print("received remote play")
} else if event.subtype == UIEvent.EventSubtype.remoteControlPause {
print("received remote pause")
} else if event.subtype == UIEvent.EventSubtype.remoteControlTogglePlayPause {
print("received toggle")
}
}
}发布于 2019-10-01 07:54:03
private var touchSurface: UITapGestureRecognizer!
private var tapGesturePlayPause: UITapGestureRecognizer!
private var tapGestureMenu: UITapGestureRecognizer!
func configure() {
self.touchSurface = UITapGestureRecognizer(target: self, action: #selector(self.yourMethod1))
self.touchSurface.allowedPressTypes = [NSNumber(value: UIPressType.select.rawValue)]
self.addGestureRecognizer(self.touchSurface)
self.tapGesturePlayPause = UITapGestureRecognizer(target: self, action: #selector(self.yourMethod2))
self.tapGesturePlayPause.allowedPressTypes = [NSNumber(value: UIPressType.playPause.rawValue)]
self.addGestureRecognizer(self.tapGesturePlayPause)
self.tapGestureMenu = UITapGestureRecognizer(target: self, action: #selector(self.yourMethod3))
self.tapGestureMenu.allowedPressTypes = [NSNumber(value: UIPressType.menu.rawValue)]
self.addGestureRecognizer(self.tapGestureMenu)
}https://stackoverflow.com/questions/57769443
复制相似问题