简体   繁体   English

通话后的iOS背景音频录音

[英]iOS background audio recording after call

I'm developing an iOS application that records audio in background. 我正在开发一个在后台录制音频的iOS应用程序。 That's work fine. 这很好用。
The problem is when a call comes in: when i'm calling the app stops to record (that's fine) but when the call ends, I need that the app start to record again. 问题是当一个电话进来时:我正在呼叫应用程序停止记录(这很好)但是当呼叫结束时,我需要应用程序开始再次记录。

Is it possible ? 可能吗 ? How can I do this ? 我怎样才能做到这一点 ?

Thanks to all. 谢谢大家。

UPDATE UPDATE

I use AudioQueueNewInput to record audio. 我使用AudioQueueNewInput来录制音频。 Now I'm trying to use this code to get incoming call: 现在我正在尝试使用此代码来接听来电:

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

I can get the ends of call on handleAudioSessionInterruption by AVAudioSessionInterruptionOptionShouldResume, but how can I restart my audio recorder? 我可以通过AVAudioSessionInterruptionOptionShouldResume获取handleAudioSessionInterruption的调用结束,但是如何重新启动录音机呢?

I tried to use to call AudioQueueStart again o simply same function that I use to start to record, but I can't see the red bar (mic in use) to know that app is recording. 我试图再次调用AudioQueueStart o只是我用来开始录制的相同功能,但我看不到红色条(使用的麦克风)知道应用正在录制。 What's wrong ? 怎么了 ?

Please see this question: Can not restart an interrupted audio input queue in background mode on iOS 请参阅此问题: 无法在iOS上以后台模式重新启动中断的音频输入队列

Yes it is possible, but to reactivate the session in the background, the audio session has to either set AudioSessionProperty kAudioSessionProperty_OverrideCategoryMixWithOthers 是的,但是要在后台重新激活会话,音频会话必须设置AudioSessionProperty kAudioSessionProperty_OverrideCategoryMixWithOthers

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

or the app has to receive remote control command events : 或者应用程序必须接收远程控制命令事件

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM