我将MPNowPlayingInfoCenter集成到音乐播放应用中。当我在iOS模拟器中运行它时,它和MPRemoteCommandCenter的集成工作得很好。当我在设备上运行相同的代码时,控制中心中的音乐控件根本不会改变。好像应用程序没有注册MPNow和MPRemote中心。
MPNowPlayingInfoCenter *np = [MPNowPlayingInfoCenter defaultCenter];
np.nowPlayingInfo = @{MPMediaItemPropertyTitle:[tracks objectAtIndex:self.currentTrack],
MPMediaItemPropertyArtist:currentArtist,
MPMediaItemPropertyAlbumTitle:currentAlbum,
MPMediaItemPropertyMediaType:@(MPMediaTypeMusic),
MPMediaItemPropertyPlaybackDuration:@(self.audioHandler.audioDuration),
MPNowPlayingInfoPropertyElapsedPlaybackTime:@(self.audioHandler.position),
MPNowPlayingInfoPropertyPlaybackRate:rate
};
我在视图控制器生命周期方法中得到了所有这些好东西:
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
// Turn off remote control event delivery
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
// Resign as first responder
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
一对夫妇注意到:
答案 0 :(得分:4)
找到它。在初始化令人惊叹的音频引擎(顺便说一句伟大的框架)时,需要告诉框架,如果想要使用MPNowPlayingInfoCenter,它不希望与其他应用程序共享音频输出。要做到这一点,我做了:
self.audioController = [[AEAudioController alloc]
initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription]
inputEnabled:NO];
self.audioController.allowMixingWithOtherApps = NO;