我正在实现音频会话中断的 C 监听器。当它被要求中断时,我会停用我的音频会话。然后当我的应用程序恢复时,我会再次激活音频会话。我为我的音频会话设置了许多属性和类别,我是否必须在重新激活后重置所有内容?
提前致谢。
一些代码供参考:
初始化、设置类别:
OSStatus error = AudioSessionInitialize(NULL, NULL, interuptListenerCallBack, (__bridge void *)(self));
UInt32 category = kAudioSessionCategory_PlayAndRecord;
error = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
if (error) printf("couldn't set audio category!");
//use speaker as default
UInt32 doChangeDefaultOutput = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(doChangeDefaultOutput), &doChangeDefaultOutput);
//allow bluethoothInput
UInt32 allowBluetoothInput = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryEnableBluetoothInput, sizeof(allowBluetoothInput), &allowBluetoothInput);
interuptListenerCallBack 是我因中断而停用和响应音频会话的地方,使用
OSStatus error = AudioSessionSetActive(false);
if (error) printf("couldn't deactivate audio session!");
或者
OSStatus error = AudioSessionSetActive(true);
if (error) printf("AudioSessionSetActive (true) failed");