title: Setting up iPhone to start playback through speakers, but allow headphone override
body: <p>I know this question has been somewhat dealt with before, but I feel like we could nail this down a bit better. </p>
  
  <p>Here is my present code. The iPhone automatically plays out the speakers (not the earpiece), but when I plug the earphones in nothing happens. I would like it so that it playback is through the speakers, but will route through the headphones if they are plugged in. How can we change this code to properly do this?</p>
  
  <pre><code>    // ORIGINAL CODE
       UInt32 category = kAudioSessionCategory_PlayAndRecord; 
       error = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &amp;category);
      if (error) printf("couldn't set audio category!");
  
   // I put this chunk in of code myself. To change the audio to go the speakers (not the earpiece).
   // I don't think this is the best way to do this.      
  
  
      UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
      AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&amp;audioRouteOverride);
  </code></pre>
  
  <p>Thanks!</p>