title: Stop AvAudioPlayer in other View iOS
body: <p>I would like to stop the audio with AvAudioPlayer but when another view dissapear, There are two views:</p>
  
  <p>The problem is that when view2 disappear, the audio doesn't stop... How I should do?</p>
  
  <p><strong>View1.h</strong></p>
  
  <pre><code>@property (nonatomic, retain) AVAudioPlayer *audioPlayer;
  
  - (IBAction)playAudio:(id)sender;
  
  - (IBAction)stopAudio:(id)sender;
  </code></pre>
  
  <p><strong>View1.m</strong></p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
       [self playSound];
  
  }
  
  - (void) playSound
  {
      NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                           pathForResource:@"simpsonsTheme"
                                           ofType:@"mp3"]];
      NSError *error;
      self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&amp;error];
      //[self.audioPlayer play];
      [self playAudio:audioPlayer];
  
  }
  
  - (IBAction)playAudio:(id)sender {
      [audioPlayer play];
  }
  
  - (IBAction)stopAudio:(id)sender {
      [audioPlayer stop];
  }
  </code></pre>
  
  <p>And <strong>View2.m</strong></p>
  
  <pre><code>-(void)viewWillDisappear:(BOOL)animated{
      view1 = (View1 *)[[UIApplication sharedApplication] delegate];
      [view1 stopAudio:view1.audioPlayer];
      }
  </code></pre>
  
  <p>In the View2 I import the View1 to do that.
  Thanks</p>