在 iOS 10 中,控制中心 UI 进行了重新设计,从那时起,播放/暂停控制按钮的响应就不同了。
不能暂停的内容不应在每次点击时更改控制中心中的播放/暂停按钮。
在 iOS 10 之前,它可能会检查 MPNowPlayingInfoPropertyPlaybackRate
,如果内容没有暂停,它不会更改 Remote 。在 iOS 10 中,它每次都会立即更改并忽略 MPNowPlayingInfoPropertyPlaybackRate
。
最佳答案
UIEvent
处理远程控制事件的委托(delegate)方式不再推荐用于音频/视频事件处理。相反,MPRemoteCommandCenter
提供基于选择器的界面来启用和禁用按钮和远程控制事件,以及处理这些事件的操作。
在不应暂停或恢复内容的情况下,您必须将每个命令的 enabled
属性显式设置为 NO
AND提供一个 Action ,即使它只是一个什么都不做的虚拟选择器,以便正确禁用控制中心中的按钮:
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)];
我用一个使用 AVPlayer 的例子进一步阐述了这一点 here .
关于ios - MPNowPlayingInfoCenter Remote 在 iOS 10 中响应不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39465072/