Take a look at the Remote Control of Multimedia documentation.
Here’s how to listen for remote control events in a UIViewController
subclass. First, make your controller participate in the responder chain, otherwise the events will be forwarded to the app delegate:
- (BOOL)canBecomeFirstResponder
{
return YES;
}
Where appropriate, tell the application to start receiving events and make your controller the first responder:
// maybe not the best place but it works as an example
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
Then respond to them:
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
[self playOrStop: nil];
break;
case UIEventSubtypeRemoteControlPreviousTrack:
[self previousTrack: nil];
break;
case UIEventSubtypeRemoteControlNextTrack:
[self nextTrack: nil];
break;
default:
break;
}
}
}