3

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.

Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • 1
    If you need this slider for changing playback position, you need to set [`changePlaybackPositionCommand`](https://developer.apple.com/documentation/mediaplayer/mpremotecommandcenter/1618997-changeplaybackpositioncommand)'s handler. See [How can I make the Control Center slider editable?](https://stackoverflow.com/questions/34321071/how-can-i-make-the-control-center-slider-editable) – Robert Dresler Mar 11 '19 at 08:35
  • You use Key-Value Observing. – El Tomato Mar 11 '19 at 08:36

1 Answers1

3

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

Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75