I am playing Apple Music from my application , the apple music player code is as -
-(void) submitAppleMusicTrackWithProductID: (NSString *) productID // productI
Instead of using -(void)remoteControlReceivedWithEvent:(UIEvent *)event
to track for the controls, use MPRemoteCommandCenter
adding targets to each one of the controls:
Note: It's important to enable the controls before assigning a target.
[MPRemoteCommandCenter sharedCommandCenter].playCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(remotePlay)];
[MPRemoteCommandCenter sharedCommandCenter].pauseCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].pauseCommand addTarget:self action:@selector(remoteStop)];
[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand addTarget:self action:@selector(loadPreviousSong)];
[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand addTarget:self action:@selector(loadNextSong)];
Selectors:
-(void) remotePlay {
[APP_DELEGATE PlayPauseMusic:nil];
}
-(void) remoteStop {
[APP_DELEGATE PlayPauseMusic:nil];
}
-(void) loadNextSong {
[APP_DELEGATE next:nil];
}
-(void) loadPreviousSong {
[APP_DELEGATE previous:nil];
}