title: iOS : How to autostop the sound file on the PickerViewController when user select a new picker?
body: <p>I have one music player with multiple sounds. My question is when i pick one of the object in the picker view, it will play automatically, but when i select a new one, the old sound won't stop. The sound will overlap with the new one. How do I autostop it? Here is my code for troubleshoot : </p>
  
  <p>H File :</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;AVFoundation/AVAudioPlayer.h&gt;
  
  @interface musixGreetingViewController : UIViewController &lt;UIPickerViewDelegate, UIPickerViewDataSource, AVAudioPlayerDelegate&gt;{
  
      UIPickerView       *picker;
      UILabel            *musicTitle;
      NSMutableArray     *musicList;
      AVAudioPlayer      *audioPlayer;
  
  
  }
  
  
  @property (nonatomic, retain) IBOutlet UIPickerView *picker;
  @property (nonatomic, retain) IBOutlet UILabel *musicTitle;
  @property (nonatomic, retain) NSMutableArray *musicList;
  
  -(IBAction)playSelectedMusic:(id)sender;
  
  
  @end
  </code></pre>
  
  <p>M File :</p>
  
  <pre><code>    - (void)viewDidLoad
      {
          [super viewDidLoad];
           musicList = [[NSMutableArray alloc] initWithObjects:@"m1",@"m2",@"m3",@"m6",@"m4", @"m5",nil];
      }
  
  -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
  
  
  {
  
      //[self playSelectedMusic:self];
  
      if ([[musicList objectAtIndex:row] isEqual:@"m1"])
      {
  
          NSString *path = [[NSBundle mainBundle] pathForResource:@"m1" ofType:@"mp3"];
          AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
  
          pickerView.delegate = self;
          [theAudio play];
  
          NSString *resultString = [[NSString alloc] initWithFormat:
                                    @"m1",
                                    [musicList objectAtIndex:row]];
          musicTitle.text = resultString;
  
  
      }
  
  
      if ([[musicList objectAtIndex:row] isEqual:@"m2"])
      {
  
          NSString *path = [[NSBundle mainBundle] pathForResource:@"m2" ofType:@"mp3"];
          AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
  
          pickerView.delegate = self;
          [theAudio play];
  
  
  
          NSString *resultString = [[NSString alloc] initWithFormat:
                                    @"m2",
                                    [musicList objectAtIndex:row]];
          musicTitle.text = resultString;
  
  
      }
  
  -(IBAction)playSelectedMusic:(id)sender{
  
  I want the music play here, how to do so without autoplay the music in the picker view?
  
  }
  </code></pre>