Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
}

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

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

like image 384
Colin Fausnaught Avatar asked Jul 16 '15 20:07

Colin Fausnaught


1 Answers

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

like image 178
papacostas Avatar answered Nov 13 '22 09:11

papacostas