title: AVAudioPlayer audioPlayerDidFinishPlaying called when the file is played second time
body: <p>I am using AVAudioPlayer class to play audio but the problem is that when I play the audio I do not receive the callback in audioPlayerDidFinishPlaying when the file is finish playing and the file starts again even when the number of loops is set to 1</p>
  
  <p>Here is the code.</p>
  
  <p><em><strong>.h</em></strong></p>
  
  <pre><code>@interface AudioController : NSObject &lt;AVAudioPlayerDelegate&gt;
  
  -(void) playBigGameTheme{
  -(void) playMusic:(NSString*) fileName isLooping: (BOOL) isLooping;
  @end
  </code></pre>
  
  <p><em><strong>.m</em></strong></p>
  
  <pre><code>@implementation AudioController{
  
      AVAudioPlayer *audioPlayer;
  }
  
  -(void) playMusic:(NSString*) fileName isLooping: (BOOL) isLooping{
  
      int loop = 1;
      if(isLooping){
          loop = -1;
      }
  
      [audioPlayer stop];
      NSURL* soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:fileName  ofType:@"mp3"]];
      audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
      audioPlayer.numberOfLoops = loop;
      [audioPlayer setDelegate:self];
      NSLog(@"===Number of loops : %d", audioPlayer.numberOfLoops);    
      [audioPlayer play];
  }
  
  - (void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
  {
      NSLog(@"HERE");
  }
  
  -(void) playBigGameTheme{
      [self playMusic:BGAME_MAIN_MUSIC_FILE_NAME isLooping:NO];
  }
  @end
  </code></pre>
  
  <p>when I call playBigGameTheme the audio starts playing correctly. but it restarts when the sound is finished and when the audio finishes the second time then only the audioPlayerDidFinishPlaying method is called.</p>
  
  <p>I am stuck and do not know whats going wrong.. </p>