How to control seeking forward and backward from control center?

1.5k views Asked by At

I really try to turn it on, but with no success;) Is there any way to do this at all?

This is how I setup remote control:

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

What do I miss?

Pause and play works perfectly.

1

There are 1 answers

0
Lukas Würzburger On BEST ANSWER

Event Handler

You need to add a handler for all the event's you want to receive:

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

Apple Documentation

... To respond to a particular event, register a handler with the appropriate MPRemoteCommand object.

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