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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With