如何禁用控制中心播放/暂停按钮?

问题描述 投票:0回答:2

我正在使用 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
    }

但是没有用..

如果我在添加为目标的测试方法上放置断点,它会得到回调但没有用。尽管如此,播放和暂停按钮仍然有效

有什么方法可以禁用这些按钮,我做得正确吗?

ios objective-c media-player avplayer control-center
2个回答
0
投票

首先,为以下内容创建新函数:

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

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


0
投票

斯威夫特

您可以像这样添加暂停命令的目标并重播

MPRemoteCommandCenter.shared().pauseCommand.addTarget { _ in
   DispatchQueue.main.async {
    player.play()
   }
  return .commandFailed
}
© www.soinside.com 2019 - 2024. All rights reserved.