AVCaptureSession addInput导致背景音频出现故障

时间:2016-02-19 03:02:31

标签: ios objective-c avfoundation avcapturesession avaudiosession

我制作视频捕捉iOS应用程序,我希望能够录制麦克风的音频,同时允许播放背景音乐。我可以做所有这些,但只要相机的视图进入和退出前景,背景音频就会跳过(暂停)。我已将错误隔离到AVCaptureSession addInput

AVCaptureSession session = [[AVCaptureSession alloc] init];
session.automaticallyConfiguresApplicationAudioSession = NO;

AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil];

// this line causes the background music to skip
[session addInput:audioDeviceInput];

如何防止添加麦克风输入影响背景音频?

fyi - in didFinishLaunchingWithOptions我设置了AVAudioSession类别:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
                                 withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker
                                       error:nil];

1 个答案:

答案 0 :(得分:3)