iOS版:Siri的不可不返回AVAudioSessionInterruptionOptionSho

2019-10-20 08:00发布

我的iOS应用程序,处理audiosession与中断:

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

在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;
}

    }

这正常工作与报警和Siri的。 但是,如果,我有没有互联网连接,我按Home键,我得到“Siri的不可用......”。 AVAudioSessionInterruptionTypeBegan被触发。 按两次为homeButton得到回到应用程序,也不AVAudioSessionInterruptionTypeEnded或AVAudioSessionInterruptionOptionShouldResume被激发。 任何变通办法?

与iPad 7.0.3迷你视网膜

Answer 1:

试验的地块表明中断,不会引发任何时候,他们应该。 有时缺少InterruptionTypeBegan进入Siri的时候,而这一切都发生相当随机目前的测试用例(Unity3D&卡林巴(libpd))。

代替applicationWillResignActive杀死音频和applicationDidBecomeActive再次启动它,因为这是工作时间的100%。

有趣的事实是,当进入从Siri的背面(无wifi,所以“Siri的不可...”出现),但一段时间后改变采样率回到机器的一半本地采样率(24000在iPad迷你)。



文章来源: iOS: Siri not available does not return AVAudioSessionInterruptionOptionShouldResume