Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make my app work with the media control buttons on lock screen?

In recent iOS versions apps have some kind of access to the media control buttons on the lock screen, like the Play/Pause button:

enter image description here

It looks like the buttons are supposed to work with the MPMusicPlayerController class, is that right? Is there a way to get the “raw” events from the buttons? Because the music player only seems to offer an API to supply a bunch of MPMediaItems. What if my app is for example a radio that needs to handle the buttons differently?

like image 517
zoul Avatar asked Dec 15 '11 10:12

zoul


People also ask

How do I control Netflix from my lock screen?

Tap the lock icon once, to change it to an unlock icon, then tap the unlock icon to access the normal Netflix controls. Tap the lock icon to change it to an unlock icon, then tap it again to unlock Netflix's controls. The process for enabling and disabling screen lock is identical on both iOS and Android.

How do you change the lockscreen buttons?

From the Home screen, tap the Menu Key > Lock screen settings. Tap Shortcuts. You can access the Shortcuts setting only when the lock screen is set to Swipe. Tap one of the icons at the bottom of the screen, then tap the app you want to replace it with.


1 Answers

After a bit more searching I have found this related question that makes things clear. The music player controller class is not really the right track, the trick is to subscribe for remote events in your controller:

- (void) viewDidAppear: (BOOL) animated
{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (BOOL) canBecomeFirstResponder
{
    return YES;
}

- (void) remoteControlReceivedWithEvent: (UIEvent*) event
{
    // see [event subtype] for details
}
like image 197
zoul Avatar answered Oct 21 '22 22:10

zoul