swiftxcodempremotecommandcenter

command center Scrubber on lock screen swift


I am trying to add scrubber to command center lock screen, I am getting this error Cannot assign to value: function call returns immutable value I don't know what it means. Any help would be appreciated.

This is how I am trying to change the position

commandCenter.changePlaybackPositionCommand.addTarget(handler: {
        (event) in
        let event = event as! MPChangePlaybackPositionCommandEvent
        self.player.currentTime() = event.positionTime  // ERROR
        return MPRemoteCommandHandlerStatus.success
    })

Solution

  • I think your player property is an AVPlayer (???), and if so you want to use the seek function to set the currentTime, not set the return value from the function...

    self.player.seek(to: CMTimeMakeWithSeconds(event.positionTime, 1000000))