title: iOS AVAudioPlayer Strange Behavior
body: <p>I have a series of short (1 second) sound clips I need to play in succession.  A class is being developed for this purpose.  I'm using the following code:</p>
  
  <pre><code>- (void) playClip: (NSData *)clipToPlay
  {
      NSError *error = nil;
      AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData: clipToPlay error:&amp;error];
      audioPlayer.numberOfLoops = 0;
      audioPlayer.volume = 1.0f;
      [audioPlayer prepareToPlay];
  
      if (audioPlayer == nil)
          NSLog(@"%@", [error description]);
      else
          [audioPlayer play];
  }
  </code></pre>
  
  <p>As can be seen, <code>clipToPlay</code> contains a sound clip as <code>NSData</code>.  The behavior of this code is strange.  If I'm running it in the debugger and set the breakpoint at the following line:</p>
  
  <pre><code>[audioPlayer play];
  </code></pre>
  
  <p>The clip plays as expected -- the debugger pauses on the line, when you step through the line, the clip plays perfectly.  If, however, I take the breakpoint out, it doesn't play at all.</p>
  
  <p>I've tried copying the <code>NSData</code> to a scratch file first, with precisely the same result.  I've also copied <code>clipToPlay</code> to another variable (using a copy, not just a pointer assignment) with identical results (I was thinking perhaps clipToPlay was getting clobbered somewhere).  I'm not getting an error logged.</p>
  
  <p>I'm really stuck on why pausing the debugger on the play method would cause this to happen like this.  Any suggestions or ideas?</p>