我制作视频捕捉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];