Flashing red status bar when setting up audio category, ios

I am building an application using gobrtc google API. When I connect two devices to the session. I turn on the audio channel so that they can talk through the devices. I know that in the webrtc library they already set sessionMode as VoiceChat, but I also need to set the category as playAndRecord because I want to play RingTone sound when someone calls when the application is in the background.

So, when I set the audioSessionCatogory to PlayAndRecord, the application freezes and the status bar will blink red for a couple of time until the connection is established.

I tried not to set the category myself, and everything worked fine, but I really need to do this in order to fulfill my purpose of the application.

Does anyone know what the problem is? I don’t know, the problem is that I am setting the category, as long as the webrtc parameter also sets it, or my code for configuring catergory is incorrect.

So this is the code that I use to change the boat.

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 using the AVAudioSession class, but this does not work the way I want, so I use this. Could this be a thread issue? Should this code run on a given thread?

Also, I get this error when switching categories:

ERROR:     [0x8731000] >aurioc> 1455: AURemoteIO@0x17dbb020: 
IOThread exiting with error 0x10004006

Thank you for your help.

+4
source share

All Articles