AVCaptureSession addInput causing glitch in background audio

喜夏-厌秋 提交于 2019-12-01 04:44:03

问题


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 I set the AVAudioSession Category:

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

回答1:


Apparently there is no workaround. https://forums.developer.apple.com/message/74778#74778



来源:https://stackoverflow.com/questions/35496563/avcapturesession-addinput-causing-glitch-in-background-audio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!