iOS: Siri not available does not return AVAudioSessionInterruptionOptionShouldResume

孤者浪人 提交于 2019-12-11 13:24:53

问题


I have iOS app that handles audiosession interrupts with:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AudioInterrupt:)
name:AVAudioSessionInterruptionNotification
object: NULL];

and in AudioInterrupt:

- (void)AudioInterrupt:(NSNotification*)notification
{

NSDictionary *interuptionDict = notification.userInfo;
// get the AVAudioSessionInterruptionTypeKey enum from the dictionary
NSInteger interuptionType = [[interuptionDict     valueForKey:AVAudioSessionInterruptionTypeKey] integerValue];
 NSNumber* seccondReason = [[notification userInfo] objectForKey:@"AVAudioSessionInterruptionOptionKey"] ;
// decide what to do based on interruption type here...
switch (interuptionType) {

        case AVAudioSessionInterruptionTypeBegan:
        [[[self pureAudioHandler] audioController] setActive: NO];
        NSLog(@"Interruption started");
            break;

        case AVAudioSessionInterruptionTypeEnded:

            NSLog(@"Interruption ended");
            break;

    }
switch ([seccondReason integerValue]) {
    case AVAudioSessionInterruptionOptionShouldResume:
      NSLog(@"Resume Audio");
      [[[self pureAudioHandler] audioController] configurePlaybackWithSampleRate:44100 numberChannels:2 inputEnabled:NO mixingEnabled:YES];
        [[[self pureAudioHandler] audioController] setActive: YES];
        break;
    default:
        break;
}

    }

This works fine with alarms and Siri. However if i have no internet connection and i press home button i get "Siri not available...". AVAudioSessionInterruptionTypeBegan is triggered. Press homebutton twice to get back into app and nor AVAudioSessionInterruptionTypeEnded or AVAudioSessionInterruptionOptionShouldResume is fired. Any workarounds?

iPad mini retina with 7.0.3


回答1:


Lot of experimenting showed that interrupts aren't fired all times as they should. Sometimes missing InterruptionTypeBegan when entering Siri, and all this happens quite randomly on current testcase (Unity3D & Kalimba(libpd)).

Instead used applicationWillResignActive for killing audio and applicationDidBecomeActive to start it again, as these are working 100% of the time.

Interesting fact is that when entering back from Siri (no wifi, so "Siri not available..." appears), it changes samplerate back to half of machines native samplerate (24000 on ipad mini) after some time.



来源:https://stackoverflow.com/questions/24404463/ios-siri-not-available-does-not-return-avaudiosessioninterruptionoptionshouldre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!