title: AVAudioPlayer UIButton - second touch stop current audio play
body: <p>I have a UIButton that when touched plays an audio file. At the moment touching the button twice in succession plays the audio file twice instead of stopping it.</p>
  
  <p>I'm looking to have the second click stop the audio file and not play a second instance. any suggestions would be very much appreciated. thanks</p>
  
  <pre><code>-(IBAction) buttonNoisePlay {
  
          NSString *pathsoundFile = [[NSBundle mainBundle] pathForResource:@"noise" ofType:@"mp4"];
          sound = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathsoundFile] error:NULL];
          sound.delegate = self;
          sound.numberOfLoops = -1;
          sound.volume = 1;   
  
              if(sound == nil || sound.playing == NO)  //if not playing
              {
  
                      [sound play];
              }
              else
              {
                      [sound stop];
              }
  }
  </code></pre>