如何解决iOS中的AVCaptureSession v AVAudioSession冲突? [英] How to resolve AVCaptureSession v AVAudioSession conflict in iOS?

查看:62
本文介绍了如何解决iOS中的AVCaptureSession v AVAudioSession冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在视图控制器中运行AVCaptureSession,但在同一控制器中,我还从使用AVAudioSession的库中调用了一个函数.我似乎无法从调试器中获取太多信息,除了它在我调用此特定库的函数时完全崩溃时.该库为libpd:

I'm trying to run an AVCaptureSession in a view controller, but within the same, I'm also calling a function from a library that uses AVAudioSession. I can't seem to get much info out of the debugger, other than it crashes exactly when I call this particular library's function. The library is libpd:

https://github.com/libpd

,它将AVAudioSession称为sharedInstance.我称libpd为:

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

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

因此可以启用混合功能,但以防万一,我已经对其进行了重新编译,以便在其启动时可以执行此操作:

so mixing is enabled, but just in case, I've recompiled it so that when it inits, I do:

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

但是,没有运气.在视图控制器中将对libpd的调用移动到viewWillAppear也不起作用.但是,如果我从视图控制器中取出调用libpd的代码,并将其放在didFinishLaunchingWithOptions中的应用程序委托中,则它会开始正常运行,并且两个会话似乎并存而不会崩溃.

but, no luck. Moving the calls to libpd to viewWillAppear within the view controller didn't work either. However, if I take the code that calls libpd out of my viewcontroller, and put it in the app delegate within didFinishLaunchingWithOptions, it then starts just fine, and the two sessions seem to co-exist without crashing.

我是否缺少有关AVCaptureSession和混合的东西?我该如何将两个会话同时存在?我不是在使用AVCapture来捕获音频,而仅是通过摄像机输入来捕获音频,所以我不应该以某种方式同时进行这两个过程吗?

Am I missing something about AVCaptureSession and mixing? How do I go about both sessions co-existing? I'm not using AVCapture to capture audio, only camera input, so shouldn't I be able to somehow have both going on?

推荐答案

在开始摄像头会话后,开始音频会话(可以将其设置为支持混音).我尝试过,您需要在开始音频会话之前等待摄像机的设置(例如,等待几秒钟)

Start the audio session (which can be set to support mixing) after you've started the camera session. I tried and you need to wait for the camera to be setup before you start the audio session (e.g. wait a couple of seconds)

这篇关于如何解决iOS中的AVCaptureSession v AVAudioSession冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆