I am working on an application that will play music from the iPod library. I play music through MPMediaPlayerController, extracting the selected item from the table and passing it to the detail view controller:
MPMediaItem *item = (MPMediaItem *)self.detailItem;
MPMediaItemCollection *collection = [[MPMediaItemCollection alloc] initWithItems:@[item]];
[self.musicPlayer setQueueWithItemCollection:collection];
[self.musicPlayer play];
Start playing music. I set the following values in my Info.plist to enable background usage:
UIBackgroundModes
>Item 0 - audio
And it works. When I close the application, the music continues to play. So now I'm trying to get the audio controls in the control center to send messages to my application, so after some reading, I found that I need to do a few things. So I created a subclass of UIResponder and added the following lines:
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
NSLog(@"CustomApp:remoteControlReceivedWithEvent:%@", event.description);
}
AppDelegate UIResponder, :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[MainWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.mainViewController = [[BrowserViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.mainViewController];
self.window.rootViewController = navigationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
, , , , , , . , NSLog UIResponder , . , , / , , , iPod .
, - , . , , , .