I have been writing code that uses [MPMusicPlayerController applicationMusicPlayer]
to play music.
This has been working successfully and will show details of the currently playing track on the Control Center screen.
Unfortunately, I can't seem to get the remote control buttons working from the Control Center screen or from the headset.
I have enabled the background audio made to the app will play in the background and have enabled some of the MPRemoteCommandCenter commands using code similar to that shown below. The code below is based on what I have seen in the documentation and in this SO question
MPRemoteCommandCenter *rcc = [MPRemoteCommandCenter sharedCommandCenter];
MPRemoteCommand *playCommand = rcc.playCommand;
playCommand.enabled = YES;
[playCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
[musicPlayer play];
NSLog(@"Play button pressed");
return MPRemoteCommandHandlerStatusSuccess;
}];
Using the code above, it will either cause the Control Center buttons to do nothing or start the Music app playing.
I'm sure there is something simple that I'm missing but can't seem to see it. I have tried calling [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
but that isn't really supposed to be used with MPRemoteCommandCenter as far as I can tell.
I am working with Xcode 6.2 and iOS 8.2.
I've tried everything I can think of here....How do I get MPRemoteCommandCenter to work as I expect it?