(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}(void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
pragma mark - Player Controll
-
(void)remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
NSMutableDictionary * info = [NSMutableDictionary dictionary];
//音乐的标题
[info setObject:@"leao" forKey:MPMediaItemPropertyTitle];
//音乐的艺术家
[info setObject:@"chocolate" forKey:MPMediaItemPropertyArtist];
//音乐的播放时间
[info setObject:@(self.audioPlayer.duration) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
//音乐的播放速度
[info setObject:@(1) forKey:MPNowPlayingInfoPropertyPlaybackRate];
//音乐的总时间
[info setObject:@(self.audioPlayer.duration) forKey:MPMediaItemPropertyPlaybackDuration];
//音乐的封面
MPMediaItemArtwork * artwork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"main_icon_review"]];
[info setObject:artwork forKey:MPMediaItemPropertyArtwork];
//完成设置
[[MPNowPlayingInfoCenter defaultCenter]setNowPlayingInfo:info];if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) { case UIEventSubtypeRemoteControlTogglePlayPause: break; case UIEventSubtypeRemoteControlPreviousTrack: break; case UIEventSubtypeRemoteControlNextTrack: break; default: break; }
}
}