我的应用正在播放背景。暂停和玩也很好,即使我的应用程序是背景使用注册为AVAudioSessionInterruptionNotification
的方法。播放背景音乐:AVAudioSessionInterruptionNotification未解锁
问题到达步骤场景:
- 启动我的应用程序 - >云的背景音乐从我的应用程序打好
- 苹果推出的音乐应用程序和游戏。 AVAudioSessionInterruptionNotification已解雇。
- 当我暂停音乐应用程序或杀死音乐应用程序。 AVAudioSessionInterruptionNotification不被解雇
代码: 我在的appdelegate这样做。 didfinishlaunching
NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError];
[[AVAudioSession sharedInstance] setActive:YES error: nil];
self.player = [[AVQueuePlayer alloc] initWithURL:[NSURL URLWithString:@"http://someurl.com:8040/;stream.mp3"]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAudioSessionEvent:) name:AVAudioSessionInterruptionNotification object:nil];
- (void) onAudioSessionEvent: (NSNotification *) notification
{
//Check the type of notification, especially if you are sending multiple AVAudioSession events here
NSLog(@"Interruption notification name %@", notification.name);
if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
NSLog(@"Interruption notification received %@!", notification);
//Check to see if it was a Begin interruption
if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
NSLog(@"Interruption began!");
} else if([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeEnded]]){
NSLog(@"Interruption ended!");
//Resume your audio
NSLog(@"Player status %i", self.player.status);
// Resume playing the audio.
[self.player play];
}
}
}
你能弄明白吗?我有同样的问题。 – user1732055
仍然存在相同的问题。 PlayAndRecord和Ambient会话类别不会收到“中断结束”通知。 SoloAmbient根本没有收到任何通知。 – kakyo
你有没有调用-removeObserver:某处?我有类似的问题,这是原因。如果你和我一样,你可能想在“removeObserver”上做一个grep/find,以防你的眼睛看不到它...... – prewett