我有问题,让播放和暂停按钮切换在MPRemoteCommandCenter。由于任何原因,音频和事件都将正常工作,但是命令中心不会将play按钮更改为暂停按钮。这是我的密码。
- (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
}

如果你们能想到什么,我很乐意帮忙。这让我发疯了
发布于 2016-01-29 09:35:01
关于我是如何解决这个问题的几点建议。阅读苹果文档,它说:“你的应用程序必须是”现在播放“的应用程序。应用程序不接收远程控制事件,直到它开始播放音频。
所以首先开始播放音频。
MPRemoteCommandCenter是一个相当独立的模块。setEnabled用于明确表示不受支持的东西。不要在事件期间使用它作为切换,AVFoundation将处理它本身。
还请注意,我在模拟器中有切换问题,它在设备上切换很好,但在模拟器中没有切换,它花了16个小时才弄清楚:)
https://stackoverflow.com/questions/31463932
复制相似问题