要启动呼叫,我们的VOIP应用程序设置一个AVAudioSession,然后构建、初始化和运行一个AUGraph。
在通话过程中,我们允许用户使用以下代码在扬声器模式之间来回切换:
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];效果很好。但是,如果我们在初始化AVAudioSession之后尝试某些AUGraph查询,例如:
AVAudioSessionDataSourceDescription *myInputDataSource = [avSession inputDataSource];结果为空。在执行AUGraphInitialize之前运行同一行代码将得到正确的非空结果。有人能解释一下这里发生了什么,以及如何在使用AVAudioSession时正确地访问AUGraph属性/方法吗?
发布于 2015-04-28 19:42:35
这是开发人员文档的预期行为,如果无法切换源,inputDataSource应该返回nil。因此,苹果确实不允许任何不好的事情通过错误配置发生,但是一个零源也会给出错误的想法。希望这能有所帮助。
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.https://stackoverflow.com/questions/29927047
复制相似问题