Scrubbing for RemoteCommandEvent not working properly

Viewed 19

I am having a problem with my scrubbing in my app where sometimes the position that I scrub to, the control centre updates and sets its slider to the position. Sometimes it just goes back to where it was originally. If I am scrubbing backwards and the slider goes to the original position in the slider, the slider keeps going onto the end of the slider. I have attached a gif of what I am on about

Scrubbing example

here is my code:

    commandCenter.changePlaybackPositionCommand.addTarget { [unowned self] event in
        
        if let event = event as? MPChangePlaybackPositionCommandEvent {
            self.player.seekTo(to: CMTime(seconds: event.positionTime, preferredTimescale: CMTimeScale(1000)))
                
            self.setupNowPlaying()
            
            return .success
        }
        return .commandFailed
        

and,

func setupNowPlaying() {
    // Define Now Playing Info
    var nowPlayingInfo = [String : Any]()
    
    nowPlayingInfo[MPMediaItemPropertyTitle] = "Testing Song"
    nowPlayingInfo[MPMediaItemPropertyArtist] = "Testing Author"
    nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate
    
    if let image = UIImage(named: "Island") {
        nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: image.size) { size in
            return image
        }
    }
    nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = player.currentTime
    nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = player.duration
    
    // Set the metadata
    MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
    
}

Thanks

0 Answers
Related