How can I use the Lock Screen iPod Controls for my own App?
I tried MPNowPlayingInfoCenter, but if I set the information it won't be displayed anywhere; Not on the lock-screen and not in airplay on AppleTV.
I use the AVPlayer to play my audio files.
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;
}
}
}
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