How to change track position on lock screen/control center?

后端 未结 3 1145
青春惊慌失措
青春惊慌失措 2020-12-28 09:37

When playing a song with the ios 7 music app the user can use slider to change song position in the lock screen/the control center. Slider is active:

3条回答
  •  [愿得一人]
    2020-12-28 10:04

    swift4 You can change track position with help of MPRemoteCommandCenter on iOS 9.1 and higher.

    let commandCenter = MPRemoteCommandCenter.shared()
    commandCenter.changePlaybackPositionCommand.isEnabled = true
    commandCenter.changePlaybackPositionCommand.addTarget(
     self, action:#selector(changePlaybackPositionCommand(_:)))
    

    and method

    @objc func changePlaybackPositionCommand(_ event:
              MPChangePlaybackPositionCommandEvent) -> MPRemoteCommandHandlerStatus {
        let time = event.positionTime
        //use time to update your track time
        return MPRemoteCommandHandlerStatus.success
    }
    

    Note that you have to do that for every command in commandCenter if you want that commend to be enabled.

提交回复
热议问题