【问题标题】:iOS background audio recording after call通话后iOS后台录音
【发布时间】:2014-04-14 05:54:33
【问题描述】:

我正在开发一个在后台录制音频的 iOS 应用程序。这很好。
问题是来电时:当我打电话时,应用程序停止录制(这很好),但是当通话结束时,我需要应用程序再次开始录制。

有可能吗?我该怎么做?

谢谢大家。

更新

我使用 AudioQueueNewInput 来录制音频。现在我正在尝试使用此代码来接听来电:

AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *categoryError = nil;
[session setActive: NO error: nil];
if (![session  setCategory:AVAudioSessionCategoryPlayAndRecord
               withOptions:AVAudioSessionCategoryOptionMixWithOthers
                     error:&categoryError]){
    NSLog(@"Error"); //no error
}
[session setActive: YES error: nil];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleAudioSessionInterruption:)
                                             name:AVAudioSessionInterruptionNotification
                                           object:session];

我可以通过 AVAudioSessionInterruptionOptionShouldResume 结束对 handleAudioSessionInterruption 的通话,但是如何重新启动我的录音机?

我尝试再次调用 AudioQueueStart 或使用与开始录制相同的函数,但我看不到红色条(正在使用麦克风)来知道该应用正在录制。怎么了?

【问题讨论】:

    标签: ios audio-recording


    【解决方案1】:

    请看这个问题: Can not restart an interrupted audio input queue in background mode on iOS

    是的,这是可能的,但要在后台重新激活会话, 音频会话必须设置 AudioSessionProperty kAudioSessionProperty_OverrideCategoryMixWithOthers

    OSStatus propertySetError = 0;
    UInt32 allowMixing = true;
    propertySetError = AudioSessionSetProperty (
                       kAudioSessionProperty_OverrideCategoryMixWithOthers,
                       sizeof (allowMixing),
                       &allowMixing);
    

    或者应用必须receive remote control command events:

    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
    

    【讨论】:

    • 我尝试使用 AudioSessionSetProperty 但似乎不起作用。我使用 AudioQueueNewInput 录制音频,并尝试先设置您的代码以创建队列。我是 iOS 世界的新手,所以也许这个评论很愚蠢。
    • 我对 AudioSessions 了解不多,但是您是否遇到任何错误,或者它只是不起作用?
    • 它不起作用。通话后应用程序未开始录制。
    • 我使用 AudioQueueNewInput 来录制音频。
    猜你喜欢
    • 2012-09-14
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多