简体   繁体   English

初始化AUGraph后的AVAudioSession属性

[英]AVAudioSession properties after Initializing AUGraph

To start a call, our VOIP app sets up an AVAudioSession, then builds, initializes and runs an AUGraph. 要开始通话,我们的VOIP应用会设置一个AVAudioSession,然后构建,初始化并运行AUGraph。

During the call, we allow the user to switch back and forth between a speakerphone mode using code such as: 在通话期间,我们允许用户使用以下代码在扬声器模式之间来回切换:

avSession = [AVAudioSession sharedInstance];
AVAudioSessionCategoryOptions categoryOptions = [avSession categoryOptions];
categoryOptions |= AVAudioSessionCategoryOptionDefaultToSpeaker;
NSLog(@"AudioService:setSpeaker:setProperty:DefaultToSpeaker=1 categoryOptions = %lx", (unsigned long)categoryOptions);
BOOL success = [avSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:categoryOptions error:&error];

Which works just fine. 哪个很好。 But if we try to certain AVAudioSession queries after the AUGraph has been initialized, for example: 但是,如果我们在初始化AUGraph之后尝试对某些AVAudioSession查询,例如:

    AVAudioSessionDataSourceDescription *myInputDataSource = [avSession inputDataSource];

the result is null. 结果为空。 Running the same line of code BEFORE we execute the AUGraphInitialize gives the correct non-null result. 在执行AUGraphInitialize之前,运行同一行代码会给出正确的非空结果。 Can anyone explain what is going on here and how to properly access AVAudioSession properties/methods while using AUGraph? 谁能解释这是怎么回事,以及在使用AUGraph时如何正确访问AVAudioSession属性/方法?

This is expected behavior per the developer documentation, inputDataSource should return nil if it is not possible to switch sources. 根据开发人员文档,这是预期的行为,如果无法切换源, inputDataSource应该返回nil So Apple is really not letting anything bad happen via a mis-config, but a nil source can also give the wrong idea. 因此,Apple确实不会通过配置错误而让任何不好的事情发生,但是无来源也可能会带来错误的想法。 Hope this helps. 希望这可以帮助。

Discussion
The value of this property is nil if switching between multiple input
sources is not currently possible. This feature is supported only on
certain devices and peripherals–for example, on an iPhone equipped with
both front- and rear-facing microphones.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM