How to resolve AVCaptureSession v AVAudioSession conflict in iOS?

I am trying to run AVCaptureSession in a view controller, but at the same time I am also calling a function from a library that uses AVAudioSession. I cannot get much information from the debugger, except that it fires when I call this particular library function. Libpd library:

https://github.com/libpd

and it calls AVAudioSession as sharedInstance. I call libpd like:

[self.audioController configurePlaybackWithSampleRate:44100 numberChannels:2 inputEnabled:YES mixingEnabled:YES] 

so mixing is turned on, but just in case, I recompiled it so that when it inserts, I do:

  UInt32 doSetProperty = 1; AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty); 

but no luck. Moving calls in libpd to viewWillAppear in the view controller didn't work either. However, if I take the code that calls libpd from my view manager and put it in the application delegate in the didFinishLaunchingWithOptions file, then it will start just fine, and both sessions seem to coexist without crashing.

Am I missing something in AVCaptureSession and mixing? How do I get along in both sessions together? I do not use AVCapture to capture audio, only the input of the camera, so should I somehow get around both?

+3
source share
2 answers

Start an audio session (which can be configured to support mixing) after you start a camera session. I tried and you need to wait for the camera to be configured before the audio session starts (for example, wait a few seconds)

+4
source

Is it possible that the library assumes that no other audio session is active and calls AudioSessionInitialize ?

Per docs "You can activate and deactivate an audio session as needed (see AudioSessionSetActive), but you must only initialize it once."

I would suggest that the authors of this library did not include functionality for the current audio session ... but it would be easy enough to dive there and comment on the initialization lines if your application always gets this function call with the audio session running (otherwise just check with if to see if you have an audio session, if you don't, initialize one, etc.)

0
source

Source: https://habr.com/ru/post/894608/


All Articles