我在 MPRemoteCommandCenter 中切换播放和暂停按钮时遇到问题。无论出于何种原因,音频和事件都将正常工作,但命令中心不会将播放按钮更改为暂停按钮。这是我的代码...
- (void)setupMPRemoteCommandCenter{
MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
MPRemoteCommand *play = [commandCenter playCommand];
[play setEnabled:YES];
[play addTarget:self action:@selector(playAudio:)];
MPRemoteCommand *pause = [commandCenter pauseCommand];
[pause setEnabled:YES];
[pause addTarget:self action:@selector(playAudio:)];
[commandCenter.skipBackwardCommand setPreferredIntervals:@[@30.0]];
MPRemoteCommand *skipBackwards = [commandCenter skipBackwardCommand];
[skipBackwards setEnabled:YES];
[skipBackwards addTarget:self action:@selector(skipBackwardEvent:)];
[commandCenter.skipForwardCommand setPreferredIntervals:@[@30.0]];
MPRemoteCommand *skipForwards = [commandCenter skipForwardCommand];
[skipForwards setEnabled:YES];
[skipForwards addTarget:self action:@selector(skipForwardEvent:)];
}
-(void)playAudio: (MPRemoteCommandHandlerStatus *)event{
[self playAction];
//playAction handles the audio pausing and toggling the play button on the app
}
如果你们能想到什么,请告诉我,我很乐意提供帮助。这让我抓狂
关于我如何解决这个问题的一些建议。
读苹果文档 https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/Remote-ControlEvents/Remote-ControlEvents.html#//apple_ref/doc/uid/TP40009541-CH7-SW1它指出“您的应用程序必须是“正在播放”应用程序。应用程序在开始播放音频之前不会接收远程控制事件”
所以首先开始播放音频。
MPRemoteCommandCenter 是一个相当独立的模块。 setEnabled 用于明确表示某些内容将不受支持。不要在事件期间将其用作切换,AVFoundation 将自行处理。
另请注意,我在模拟器中切换时遇到了问题,它在设备上切换得很好,但在模拟器中却不行,我花了 16 个小时才弄清楚:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)