MPRemoteCommandCenter暂停/播放按钮不切换? [英] MPRemoteCommandCenter pause/play button not toggling?

查看:259
本文介绍了MPRemoteCommandCenter暂停/播放按钮不切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MPRemoteCommandCenter中切换播放和暂停按钮时遇到问题.无论出于何种原因,音频和事件都将正常运行,但是命令中心不会将播放"按钮更改为暂停"按钮.这是我的代码...

I'm having issues getting the play and pause buttons toggle in the MPRemoteCommandCenter. For whatever reason the audio and events will all work correctly, but the command center doesn't change the play button to the pause button. Here's my code...

- (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
}

让我知道你们是否可以想到任何事情,我很乐意提供帮助.这让我发疯了

Let me know if you guys can think of anything, I'd love the help. This has been driving me nuts

推荐答案

有关如何解决此问题的一些提示. 阅读苹果

a few pointers on how I solved this. reading the apple documentation it states "Your app must be the "Now Playing" app. An app does not receive remote control events until it begins playing audio"

所以首先开始播放音频.

so first start playing the audio.

MPRemoteCommandCenter是一个非常自力更生的模块. setEnabled用于明确表示将不支持某些内容.请勿在事件期间将其用作切换按钮,AVFoundation会自行处理.

MPRemoteCommandCenter is a fairly self reliant module. setEnabled is used to explicitly say something is not going to be supported. Do not use it as a toggle during an event, AVFoundation will handle that itself.

还请注意,我在模拟器中切换时遇到问题,它可以在设备上(但在模拟器中)切换得很好,这花了16个小时才弄清楚了:)

Also note that i had issues toggling in the simulator, it toggles fine on device but not in the simulator, which took a quick 16 hours to figure out :)

这篇关于MPRemoteCommandCenter暂停/播放按钮不切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆