1

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

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

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))
}

我想念什么?

暂停和播放完美。

4

1 回答 1

2

事件处理程序

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

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

苹果文档

...要响应特定事件,请使用适当的 MPRemoteCommand 对象注册处理程序。

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

于 2019-03-11T08:39:58.393 回答