title: iOS - Device, if muted, hangs when setting kAudioSessionProperty_AudioCategory
body: <p>I have an issue where I'm trying to change my Audio Category on AVAudioSession, to start recording microphone input.</p>
  
  <p>If I do this with my current implementation (and lots of alternative implementations, to try and solve this issue) when the device's mute switch is not set (i.e. unmuted), then everything's fine.</p>
  
  <p>If I do this when muted - coming from any prior audio category (MediaPlayback, SoloAmbient etc.), there's a huge delay, and it results in the device behaving very sluggish for a while.</p>
  
  <p>Here's what I'm doing. On app startup, I do this:</p>
  
  <pre><code>AudioSessionInitialize(NULL, NULL, NULL, NULL);
  UInt32 sessionCategory = kAudioSessionCategory_SoloAmbient;
  AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &amp;sessionCategory);
  AudioSessionSetActive(true);
  </code></pre>
  
  <p>and later, to start recording:</p>
  
  <pre><code>AudioSessionInitialize(NULL, NULL, NULL, NULL);
  UInt32 sessionCategory = kAudioSessionCategory_RecordAudio;
  AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &amp;sessionCategory);
  AudioSessionSetActive(true);
  </code></pre>
  
  <p>If I debug and step through, everything's as fast as expected until I hit AudioSessionSetProperty - that's where the device is hanging. It happens when I use either of the RecordAudio and PlayAndRecord categories.</p>
  
  <p>When this happens, I get the following messages in the console:</p>
  
  <pre><code>AudioSessionSetProperty posting message to kill mediaserverd
  AudioSessionSetActive posting message to kill mediaserverd
  AudioQueueSetProperty posting message to kill mediaserverd
  AllocateBuffer posting message to kill mediaserverd
  </code></pre>
  
  <p>I've searched online for these but they are never reported alongside this kind of delay I'm experiencing, and they also don't highlight what I might be doing wrong.</p>
  
  <p>Has anyone experienced anything similar, and do you know what I can do to resolve this?</p>
  
  <p>Thanks in advance</p>