Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPod Controls in Lockscreen for own App

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.

like image 312
Jeanette Müller Avatar asked Dec 16 '22 05:12

Jeanette Müller


1 Answers

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;
        }
    }
}
like image 190
Ryder Mackay Avatar answered Dec 26 '22 13:12

Ryder Mackay