【问题标题】:tvOS Background Music and Play/Pause ButtontvOS 背景音乐和播放/暂停按钮
【发布时间】:2019-10-04 19:46:45
【问题描述】:

我目前正在 tvOS 中制作 SpriteKit 游戏,并使用遥控器上的播放/暂停按钮作为我的游戏辅助按钮。完成这项工作的代码如下:

let pushPlay = UITapGestureRecognizer(target: self, action: #selector(pushedPlay))
pushPlay.allowedPressTypes = [NSNumber(value: UIPress.PressType.playPause.rawValue)]
self.view?.addGestureRecognizer(pushPlay)

这很好用,但会阻止 Apple Music 应用在后台播放任何音乐。由于我的游戏是纸牌游戏,因此我更愿意允许用户播放自己的音乐,如果他们愿意的话。我在 tvOS 上的大多数 Apple 应用上都注意到了这种行为,想知道是否有任何方法可以在按下播放/暂停按钮时覆盖音乐暂停?

谢谢

【问题讨论】:

  • 你试过pushPlay.cancelsTouchesInView 吗?真的

标签: swift sprite-kit tvos


【解决方案1】:

如果你覆盖默认动作而不是添加手势

override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
  if(presses.first?.type == UIPressType.PlayPause) {
    pushedPlay()
    // don't call to super class 
    } 
}

【讨论】:

  • 刚刚试了一下,但不幸的是,如果在后台播放音乐并且按下了播放/暂停按钮,它不会被调用。
猜你喜欢
  • 1970-01-01
  • 2014-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多