简体   繁体   中英

MPRemoteCommandCenter pause/play button not toggling?

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 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.

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM