title: iOS - How to stop background music when changing views
body: <p>How to stop background music when changing views? I have no clue. If i press a button which takes me to a new view, there is new background music. But the old background music (which goes in an infinite loop) keeps on going. Please help! also sample some code please, here is mine:</p>
  
  <pre><code>- (void)viewDidLoad {
      NSString *path = [[NSBundle mainBundle] pathForResource:@"MathMusic2" ofType:@"wav"];
      AVAudioPlayer* theAudio= [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
      theAudio.delegate = self;
      [theAudio play];
      theAudio.numberOfLoops = -1;
  
      [super viewDidLoad];
  }
  </code></pre>
  
  <p>I just need to know how to make the background music from the new view stop playing. And vice versa when i press the back button from the new view</p>