Ответ 1
У меня была аналогичная проблема с прерываниями. iOS: Siri недоступен не возвращает AVAudioSessionInterruptionOptionShouldResume
Завершено вместо использования applicationWillResignActive и applicationDidBecomeActive.
Мое приложение хорошо играет в . Пауза и play также хорошо работает, даже мое приложение является фоном, используя методы, зарегистрированные для 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];
}
}
}
У меня была аналогичная проблема с прерываниями. iOS: Siri недоступен не возвращает AVAudioSessionInterruptionOptionShouldResume
Завершено вместо использования applicationWillResignActive и applicationDidBecomeActive.
Существует свойство вашего экземпляра AVCaptureSession: @property (неатомный) BOOL используетApplicationAudioSession
Это значение YES по умолчанию просто устанавливает значение НЕТ и будет работать нормально.
Попробуйте добавить объект: session
[[NSNotificationCenter defaultCenter] addObserver: self селектор: @selector (onAudioSessionEvent:) name: объект AVAudioSessionInterruptionNotification: [AVAudioSession sharedInstance]];