I am creating an app that use google webrtc API. When I connect two devices into a session. I enable audio channel so that they can talk through the devices. I know that in the webrtc Library, they already setting the sessionMode to be VoiceChat, but I have to set the category to be playAndRecord myself as well because I want to play a ringTone sound when someone calls when the app is in the background.
So When I setting the audioSessionCatogory to PlayAndRecord, the app will freeze and the status bar will flash red for couple time before the connection is established.
I tried not to set category by myself and everything works fine, but I really need to do so in order to fulfill my goal of the app.
Does anyone know what the problem might be? I do not know if it is a problem of I am setting the category while the webrtc is setting it as well, or my code for setting the catergory is not correct.
So this is the code I use to change the catergory.
UInt32 value = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(value), &value);
value = YES;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(value), &value);
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(value), &value);
value = kAudioSessionMode_VoiceChat;
AudioSessionSetProperty(kAudioSessionProperty_Mode, sizeof(value), &value);
AudioSessionSetActive(YES);
I tried to use the AVAudioSession class intead, but that does not work out the way I want, so I am using this. Could this be a thread problem? Does this code need to be run in a specify thread?
Also, I am getting this Error when I switch Category:
ERROR: [0x8731000] >aurioc> 1455: AURemoteIO@0x17dbb020:
IOThread exiting with error 0x10004006
Thank you for all your helps