简体   繁体   中英

Change lock screen button in iOS

I am developing a music application and I have managed to control lock screen events with "MPNowPlayingInfoCenter". I want to know is it possible to hide next and previous button and just display play/pause and slider? How?

And is it possible to change the pause button to stop or not? Also I was looking forward to change music using lock screen slider but I couldn't find any clear answer.

It is possible to hide or disable any of the player actions in the control center on the lock screen.

If you want to keep the icon, but leave it in the disabled state, you need to explicitly disable the command, as well as set an action to it.

commandCenter.previousTrackCommand.enabled = NO;
[commandCenter.previousTrackCommand addTarget:self action:@selector(previousTapped:)]; // or some dummy selector, this will never be called
commandCenter.nextTrackCommand.enabled = NO;
[commandCenter.nextTrackCommand addTarget:self action:@selector(nextTapped:)]; // or some dummy selector, this will never be called

If you do not want the button to appear at all, don't set the the command to be enabled, or set its action.

To set the Pause command, enable it and set an action:

commandCenter.pauseCommand.enabled = YES;
[commandCenter.pauseCommand addTarget:self action:@selector(pauseAudio)];

You can then implement a pauseAudio method which pauses or stops your player.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM