iOS:无法使用Siri不会返回AVAudioSessionInterruptionOptionShouldResume [英] iOS: Siri not available does not return AVAudioSessionInterruptionOptionShouldResume

查看:126
本文介绍了iOS:无法使用Siri不会返回AVAudioSessionInterruptionOptionShouldResume的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用程序,可通过以下方式处理音频会话中断:

I have iOS app that handles audiosession interrupts with:

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

和在AudioInterrupt中:

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

    }

这对于警报和Siri可以正常工作.但是,如果我没有互联网连接,并且按主页按钮,则会显示"Siri不可用...". AVAudioSessionInterruptionTypeBegan被触发.两次按下homebutton返回应用程序,也不会触发AVAudioSessionInterruptionTypeEnded或AVAudioSessionInterruptionOptionShouldResume.有任何解决方法吗?

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?

装有7.0.3的iPad mini视网膜

iPad mini retina with 7.0.3

推荐答案

大量实验表明,并不是每次都可以触发中断.有时在进入Siri时会丢失InterruptionTypeBegan,而这一切都是在当前测试用例(Unity3D和Kalimba(libpd))上随机发生的.

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)).

而不是使用applicationWillResignActive杀死音频,并使用applicationDidBecomeActive重新启动它,因为它们100%的时间都在工作.

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

有趣的事实是,当从Siri重新输入时(没有wifi,因此出现"Siri不可用..."),它会在一段时间后将采样率变回机器原始采样率的一半(在ipad mini上为24000).

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.

这篇关于iOS:无法使用Siri不会返回AVAudioSessionInterruptionOptionShouldResume的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆