简体   繁体   中英

How to disable Control Centre play/pause buttons?

I'm using AV Player, to play some videos in my apps, But if I open Control Centre and try to play and pause the video, it is playing and pausing, But I don't want that feature. I want to disable this functionality.So for this, I did like this...

MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
    remoteCommandCenter.playCommand.enabled = NO;
    remoteCommandCenter.pauseCommand.enabled = NO;
    remoteCommandCenter.previousTrackCommand.enabled = NO;
    remoteCommandCenter.nextTrackCommand.enabled = NO;

This didn't work, then

    MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
    remoteCommandCenter.playCommand.enabled = YES;
    [remoteCommandCenter.playCommand addTarget:self action:@selector(test)];
    remoteCommandCenter.pauseCommand.enabled = YES;
    [remoteCommandCenter.pauseCommand addTarget:self action:@selector(test)];
    remoteCommandCenter.previousTrackCommand.enabled = NO;
    remoteCommandCenter.nextTrackCommand.enabled = NO;

    - (void)test {

// Not doing anything
    }

Then Another way I tried,

MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
    remoteCommandCenter.playCommand.enabled = NO;
    [remoteCommandCenter.playCommand addTarget:self action:@selector(test)];
    remoteCommandCenter.pauseCommand.enabled = NO;
    [remoteCommandCenter.pauseCommand addTarget:self action:@selector(test)];
    remoteCommandCenter.previousTrackCommand.enabled = NO;
    remoteCommandCenter.nextTrackCommand.enabled = NO;

    - (void)test {

// Not doing anything
    }

But there is no use..

If I put a breakpoint at test method that I added as a target, It is getting the callback but no use. Still, play and pause buttons are working

Is there any way to disable to these buttons, Am I doing it correctly or not ?

First of all, make new function for:

remoteCommandCenter.pauseCommand.enabled = NO;
[remoteCommandCenter.pauseCommand addTarget:self action:@selector(test)];

ie pause something like this because application became crash.

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