ios - MPNowPlayingInfoCenter Remote 在 iOS 10 中响应不正确

标签 ios objective-c swift ios10 mpnowplayinginfocenter

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/

相关文章:

ios - 在应用程序中显示带有自定义 UINavigationBar 主题的 MFMailComposer 的白色 UINavigationBar

ios - Wi-Fi 直连和 iOS 支持

ios - 我已经隐藏了导航栏和状态栏,现在屏幕边缘平移手势返回不起作用,这是典型的吗?

objective-c - 为两个不同的 View 使用自定义键盘

swift - 使用组合的自定义更改运算符

ios - Objective C/Swift 如何打开 base64 url​​?

android - 在移动应用程序(iOS/Android)上显示我的栅格 map

ios - 自定义 UITableView 中的单元格出队

json - 保持用户快速登录

ios - 仅获取共享特定属性值的核心数据对象