代码之家  ›  专栏  ›  技术社区  ›  Bartłomiej Semańczyk

如何控制从控制中心向前和向后搜索?

  •  0
  • Bartłomiej Semańczyk  · 技术社区  · 7 年前

    我真的试着打开它,但没有成功;)有没有办法做到这一点?

    这是我设置遥控器的方式:

    private func setupRemoteControl() {
        commandCenter.previousTrackCommand.isEnabled = false
        commandCenter.nextTrackCommand.isEnabled = false
        commandCenter.skipBackwardCommand.isEnabled = false
        commandCenter.skipForwardCommand.isEnabled = false
        commandCenter.seekForwardCommand.isEnabled = true
        commandCenter.seekBackwardCommand.isEnabled = true
        commandCenter.changePlaybackPositionCommand.isEnabled = true
        commandCenter.playCommand.isEnabled = true
        commandCenter.pauseCommand.isEnabled = true
        commandCenter.playCommand.addTarget(self, action: #selector(play))
        commandCenter.pauseCommand.addTarget(self, action: #selector(pause))
    }
    

    我错过了什么?

    暂停和玩耍效果很好。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Lukas Würzburger Chadwick Wood    7 年前

    事件处理程序

    您需要为要接收的所有事件添加一个处理程序:

    commandCenter.changePlaybackPositionCommand.addTarget(handler: { (event) in
        // Handle position change
        return MPRemoteCommandHandlerStatus.success
    })
    

    苹果文档

    ... 要响应特定事件,请向相应的MPRemoteCommand对象注册处理程序。

    https://developer.apple.com/documentation/mediaplayer/mpremotecommand

    推荐文章