AVCaptureSession addInput导致背景音频出现故障 [英] AVCaptureSession addInput causing glitch in background audio
问题描述
我正在制作视频捕捉iOS应用程序,我希望能够录制麦克风的音频,同时允许播放背景音乐。我可以做所有这些,但只要相机的视图进入和退出前景,背景音频就会跳过(暂停)。我已将错误隔离到 AVCaptureSession addInput
:
I'm making a video capturing iOS app and I want to be able to record audio from the microphone while allowing background music to play. I can do all of this but the background audio skips (pauses briefly) whenever the view with the camera enters and exits the foreground. I have isolated the bug to 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];
如何防止添加麦克风输入影响背景音频?
How can I prevent adding microphone input from affecting the background audio?
fyi - in didFinishLaunchingWithOptions
我设置了AVAudioSession类别:
fyi - in didFinishLaunchingWithOptions
I set the AVAudioSession Category:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker
error:nil];
推荐答案
显然没有解决方法。
https://forums.developer.apple.com/message/74778#74778
Apparently there is no workaround. https://forums.developer.apple.com/message/74778#74778
这篇关于AVCaptureSession addInput导致背景音频出现故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!