MPNowPlayingInfoCenter 遥控器在 iOS 10 中响应不正确

Jak*_*lář 3 objective-c ios mpnowplayinginfocenter swift ios10

iOS 10 中控制中心UI 进行了重新设计,从那时起,播放/暂停控制按钮的响应有所不同。

无法暂停的内容不应在每次点击时更改控制中心的播放/暂停按钮。

iOS 10之前,它可能正在检查MPNowPlayingInfoPropertyPlaybackRate,如果内容没有暂停,它不会更改遥控器。在iOS 10 中,它每次都会立即更改,而忽略MPNowPlayingInfoPropertyPlaybackRate.

JAL*_*JAL 5

UIEvent处理远程控制事件的委托方式不再推荐用于音频/视频事件处理。相反,MPRemoteCommandCenter它提供了一个基于选择器的界面来启用和禁用按钮和远程控制事件,以及处理这些事件的操作。

在内容不应被暂停或恢复的情况下,你必须明确地设定enabled每个命令属性NO 提供一个动作,哪怕仅仅是一个虚拟选择什么也不做,为了禁止在控制中心的按钮适当地:

MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];

commandCenter.playCommand.enabled = NO;
[commandCenter.playCommand addTarget:self action:@selector(playAudio)];

commandCenter.pauseCommand.enabled = NO;
[commandCenter.pauseCommand addTarget:self action:@selector(pauseAudio)];
Run Code Online (Sandbox Code Playgroud)

我在这里通过使用 AVPlayer 的示例进一步详细说明了这一点