How to update playback position in control center?
Asked Answered
S

1

4

This is how I observe changes from command center:

    commandCenter.playCommand.addTarget(self, action: #selector(play))
    commandCenter.pauseCommand.addTarget(self, action: #selector(pause))
    commandCenter.changePlaybackPositionCommand.addTarget { event in
        let seconds = (event as? MPChangePlaybackPositionCommandEvent)?.positionTime ?? 0
        let time = CMTime(seconds: seconds, preferredTimescale: 1)
        self.player.seek(to: time)
        return .success
    }

When I change position of slider, my app receives callback and position of audio is updated, but... position of slider in control center brings back to the previous state. Why?

The question is:

Why it doesn't stay where I left the finger, instead of getting back to the previous position?

Slouch answered 11/3, 2019 at 11:9 Comment(0)
B
7

You have to set MPNowPlayingInfoPropertyPlaybackRate, MPMediaItemPropertyPlaybackDuration and MPNowPlayingInfoPropertyElapsedPlaybackTime of nowPlayingInfo. You want to update nowPlayingInfo every time you play/pause/skip.

Befoul answered 18/3, 2019 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.