【问题标题】:Audio Unit - Messing up recording音频单元 - 搞砸录音
【发布时间】:2015-09-20 15:30:31
【问题描述】:

抱歉,问题介绍太长了。

在我的应用中,我正在使用录制音频并设置要录制的类别

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryRecord error:&err];

当广告网络显示插页式广告时,录制后全部静音(录制中没有声音)。由于这种情况仅发生在实时网络上的用户身上,因此我无法在最后重现它。

在日志中,我从指向 webkit 代码的用户那里得到“>>>> frameSizeChanged = 4096https://github.com/WebKit/webkit/blob/master/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp

这看起来像一些进程正在保留音频单元设置,即使在完成(释放/释放)之后也不放手。

问题:有没有办法清理其他模块设置的音频单元?只需要重置,以便在广告显示后在应用中再次进行录制。

我已尝试捕获“AVAudioSessionInterruptionNotification”,但没有。非常感谢任何帮助

【问题讨论】:

    标签: ios webkit audiounit avaudiosession interstitial


    【解决方案1】:

    您需要处理音频系统中断的问题。许多事情都会导致您的音频中断: - 在您的应用运行时接听电话 - 其他运行的应用程序使用音频 - iOS 需要播放声音 - 等等

    您的应用需要检测到这种中断,因为您的应用的音频会话将被静音。中断完成后,您需要重新启动会话。

    设置监听器作为会话设置的第一步

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourInterruptionListener:) name:AVAudioSessionInterruptionNotification object:nil];
    

    在你的中断监听器中,处理被中断的情况并处理重启你的会话

    -(void) yourInterruptionListener:(NSNotification*) aNotification
    {
        NSLog(@"Interruption happened");
        NSDictionary *interruptionDict = aNotification.userInfo;
        NSNumber* interruptionTypeValue = [interruptionDict valueForKey:AVAudioSessionInterruptionTypeKey];
        NSUInteger interruptionType = [interruptionTypeValue intValue];
        if ( interruptionType == AVAudioSessionInterruptionTypeBegan)
        {
            // stop your audio session here
            AVAudioSession *session = [AVAudioSession sharedInstance];
            NSError *errorInAudio   = nil;
            [session setActive:NO error:&errorInAudio];
        }
        else if ( interruptionType == AVAudioSessionInterruptionTypeEnded )
        {
            // Your interruption ended, restart the session
            // call or paste your session startup code here
        }
        else if ( interruptionType == AVAudioSessionInterruptionOptionShouldResume )
        {
    
    
        }
        else
        {
                    NSLog(@"Some other interruption");
        }
    
    }
    

    如果您需要模拟用户的行为,请启动您的应用,然后从另一部手机呼叫您自己。它肯定会打断你的音频。

    【讨论】:

    • 感谢您的建议。我确实有中断处理程序,当应用程序进入后台或其他中断期间会调用它。虽然当应用程序面临无声录音的问题时,它没有被调用,所以我假设它不是因为中断。
    • 进入后台是可以捕获的应用生命周期状态。您是否为 AVAudioSessionInterruptionNotification 添加了观察者?
    • 与您描述的完全相似,但没有运气。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    相关资源
    最近更新 更多