要开始通话,我们的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];
哪种方法效果很好。但是,如果我们在初始化AUGraph之后尝试某些AVAudioSession查询,例如:
AVAudioSessionDataSourceDescription *myInputDataSource = [avSession inputDataSource];
结果为null。在执行AUGraphInitialize之前运行相同的代码行会给出正确的非null结果。任何人都可以解释这里发生了什么,以及如何在使用AUGraph时正确访问AVAudioSession属性/方法?
答案 0 :(得分:1)
这是developer文档的预期行为,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.
。所以Apple真的不会通过错误的配置让任何不好的事情发生,但是零源也可能会给出错误的想法。希望这会有所帮助。
@SuppressLint("SimpleDateFormat")
public class Startbildschirm extends ActionBarActivity
{
final int PIC_CROP = 2;
static final int REQUEST_TAKE_PHOTO = 1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_startbildschirm);
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.startbildschirm, menu);
return true;
}