MPRemoteCommandCenter暂停/播放按钮没有切换?

时间:2015-07-16 20:29:01

标签: ios objective-c media-player

我在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
}

This is the issue, the media center should show a pause button like the app rather than a play button.

如果你们能想到任何事情,请告诉我,我很乐意帮助他们。这让我疯狂

1 个答案:

答案 0 :(得分:10)

关于我如何解决这个问题的一些指示。 阅读苹果documentation它声明“您的应用必须是”正在播放“应用。应用在开始播放音频之前不接收遥控事件”

所以先开始播放音频。

MPRemoteCommandCenter是一个相当自立的模块。 setEnabled用于明确表示不支持某些内容。在事件发生期间不要将它用作切换,AVFoundation将自行处理。

另请注意,我在模拟器中切换问题,它在设备上切换正常,但在模拟器中没有切换,这需要花费16个小时才能搞清楚:)