首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MPRemoteCommandCenter暂停/播放按钮不切换?

MPRemoteCommandCenter暂停/播放按钮不切换?
EN

Stack Overflow用户
提问于 2015-07-16 20:29:00
回答 1查看 3.5K关注 0票数 13

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

代码语言:javascript
复制
- (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
}

如果你们能想到什么,我很乐意帮忙。这让我发疯了

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-29 09:35:01

关于我是如何解决这个问题的几点建议。阅读苹果文档,它说:“你的应用程序必须是”现在播放“的应用程序。应用程序不接收远程控制事件,直到它开始播放音频。

所以首先开始播放音频。

MPRemoteCommandCenter是一个相当独立的模块。setEnabled用于明确表示不受支持的东西。不要在事件期间使用它作为切换,AVFoundation将处理它本身。

还请注意,我在模拟器中有切换问题,它在设备上切换很好,但在模拟器中没有切换,它花了16个小时才弄清楚:)

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31463932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档