如何禁用Control Center播放/暂停按钮?

时间:2016-09-24 15:52:37

标签: ios objective-c media-player avplayer control-center

我正在使用AV播放器,在我的应用中播放一些视频,但如果我打开控制中心并尝试播放和暂停视频,它就会播放和暂停,但我不想要这个功能。我想禁用此功能。所以,我确实喜欢这个......

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

这不起作用,然后

    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
    }

然后我尝试了另一种方式,

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
    }

但是没有用......

如果我在测试方法中添加一个断点作为目标,它将获得回调但没有用处。仍然,播放和暂停按钮正在工作

有没有办法禁用这些按钮,我是否正确执行?

1 个答案:

答案 0 :(得分:0)

首先,为:

创建新功能
remoteCommandCenter.pauseCommand.enabled = NO;
[remoteCommandCenter.pauseCommand addTarget:self action:@selector(test)];

即。暂停这样的事情,因为应用程序崩溃了。