enf*_*fix 5 audio-recording ios
我正在开发一个在后台录制音频的 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];
Run Code Online (Sandbox Code Playgroud)
我可以通过 AVAudioSessionInterruptionOptionShouldResume 获取 handleAudioSessionInterruption 的通话结束,但是如何重新启动录音机?
我尝试使用再次调用 AudioQueueStart o 只是与我用来开始录制的功能相同的功能,但我看不到红色条(正在使用麦克风)来知道应用程序正在录制。怎么了 ?
请参阅这个问题: Can not restart an interrupted audio input queue in background mode on iOS
是的,这是可能的,但要在后台重新激活会话,音频会话必须设置 AudioSessionProperty kAudioSessionProperty_OverrideCategoryMixWithOthers
Run Code Online (Sandbox Code Playgroud)OSStatus propertySetError = 0; UInt32 allowMixing = true; propertySetError = AudioSessionSetProperty ( kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (allowMixing), &allowMixing);或者应用程序必须接收远程控制命令事件:
Run Code Online (Sandbox Code Playgroud)[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self becomeFirstResponder];
| 归档时间: |
|
| 查看次数: |
951 次 |
| 最近记录: |