title: kAudioSessionOverrideAudioRoute_Speaker issue
body: <p>i need to trigger the iphone audio route back and forth from speaker to normal mode very quickly. I've created an audio Session similar to this site: </p>
  
  <p><a href="http://atastypixel.com/blog/using-remoteio-audio-unit/" rel="nofollow">http://atastypixel.com/blog/using-remoteio-audio-unit/</a></p>
  
  <p>Im creating a app that can do VOIP.</p>
  
  <p>So let me explain the simple issue i have.  I have a button that toggles from speaker to normal mode like this:</p>
  
  <pre>
  if(speakerState){
          value = kAudioSessionOverrideAudioRoute_None;
          error = AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(value), &value);
          speakerState = false;
  }
  else {
          value = kAudioSessionOverrideAudioRoute_Speaker;
          error = AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(value), &value);
          speakerState = true;
  }
  </pre>
  
  <p>... you get the idea just toggling the speaker on and off.  </p>
  
  <p>Here is the issue:  When the end user RAPIDLY hits the button to toggle the speaker after about 10 presses the application freezes for a while as if its releasing something and after 30 seconds comes back.  I need the end user to be able to constantly tap this button on/off as much as they want.  </p>
  
  <p>update:  I tried calling the speakers in the background thread but still if i press the speakers too many times it freezes or i loose audio here is the code:</p>
  
  <p>-(void) manageSpeakerState{</p>
  
  <pre><code>OSStatus error;
  UInt32 value;
  
  if(speakerState){
      value = kAudioSessionOverrideAudioRoute_None;
      error = AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(value), &amp;value);
  
      speakerBtn.selected = false;
      speakerState = false;
  }
  else {
  
      value = kAudioSessionOverrideAudioRoute_Speaker;
      error = AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(value), &amp;value);
  
      speakerBtn.selected = true;
      speakerState = true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>// this gets called whenever the speaker button is pressed ..it toggles the speakers on/off
  -(IBAction) speaker
  {</p>
  
  <pre><code>[self performSelectorInBackground:@selector(manageSpeakerState) withObject:nil ]; 
  
  
  }
  </code></pre>
  
  <p><strong>UPDATE: My audio session is running on a seperate thread using pthread and its in a .c file.  It could be a concurrency issue as it seems when the main thread gets tied up this issue occurs.  How can i update the audio route on the thread that the audio session is running on ?</strong></p>
  
  <p>UPDATE: i have the same issue as this:    <a href="http://lists.apple.com/archives/coreaudio-api/2012/Jul/msg00129.html" rel="nofollow">http://lists.apple.com/archives/coreaudio-api/2012/Jul/msg00129.html</a></p>
  
  <p>Whenever i change routes (ie. speaker or headphone) my audioUnits are paused so im reading empty stuff into the buffers.  Its almost like a hardware manufacturer issue.  How can i get around this ? the call backs are still being called but theres no audio unit while switching routes. </p>