title: AVAudioPlayer working in Simulator, but not on device
body: <p>My mp3 playing code is:</p>
  
  <pre><code>NSError *error;
  soundObject = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:audioPathString] error:&amp;error];
  if (soundObject == nil) NSLog(@"%@", [error description]);
  soundObject.delegate = self;
  soundObject.numberOfLoops = 0;
  soundObject.volume = 1.0;
  NSLog(@"about to play");
  [soundObject prepareToPlay];
  [soundObject play];
  NSLog(@"[soundObject play];");
  </code></pre>
  
  <p>The mp3 used to play fine, and it <strong>still does on the simulator</strong>. But not on the device. </p>
  
  <p>I've recently added some sound recording code (not mine) to the software. It uses AudioQueue stuff which is slightly beyond me. Does that conflict with AVAudioPlayer? Or what could be the problem? I've noticed that as soon as the audiorecording code starts working, I can't adjust the volume on the device anymore, so maybe it blocks the audio playback?.</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>The solution seems to be to put this in my code. I put it in applicationDidFinishLaunching:</p>
  
  <pre><code>[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil]; 
  UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&amp;audioRouteOverride);
  </code></pre>
  
  <p>The first line allows both play and record, whilst the other lines apparently reroute things to make the volume louder. </p>
  
  <p>All audio code is voodoo to me.</p>