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

后端 未结 3 1146
青春惊慌失措
青春惊慌失措 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 09:57

    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;
    }
    

提交回复
热议问题