正在尝试捕获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")
}
}
}
答案 0 :(得分:0)
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)
}