내 앱이 백그라운드에서 으로 재생 중입니다.일시 중지 및 재생도 내 응용 프로그램이 배경은 AVAudioSessionInterruptionNotification
에 등록 된 방법을 사용하여 잘 작동합니다.배경 음악 재생 : AVAudioSessionInterruptionNotification가 실행되지 않음
문제는 시나리오 단계를 도착 :
- 실행 내 응용 프로그램 -> 잘
- 출시 사과의 음악 응용 프로그램을 재생하고 재생 내 응용 프로그램에서 배경 음악을 간다. AVAudioSessionInterruptionNotification 해고.
- 음악 앱을 일시 중지하거나 음악 앱을 종료 할 때. AVAudioSessionInterruptionNotification는
코드를 해고하지 않습니다 나는 AppDelegate에에서이 일을하고 .
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