iosios7remote-controlcontrol-center

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


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:

enter image description here

But when playing music in my app user can't do it. Slider isn't active:

enter image description here

How can i enable these feature in my app?


Solution

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

    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_0) {
                MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
                [commandCenter.changePlaybackPositionCommand setEnabled:true];
                [commandCenter.changePlaybackPositionCommand addTarget:self action:@selector(changedThumbSliderOnLockScreen:)];
            }
    

    and method

    - (MPRemoteCommandHandlerStatus)changedThumbSliderOnLockScreen:(MPChangePlaybackPositionCommandEvent *)event
    {
        // change position
        [self setCurrentPlaybackTime:event.positionTime];
        // update MPNowPlayingInfoPropertyElapsedPlaybackTime
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
    
        return MPRemoteCommandHandlerStatusSuccess;
    }