views:

46

answers:

1

This code works fine until I exit the view and try to come back into it. If I do this, the stop button no longer works. How do I get it to still work after leaving the view?

-(IBAction)musiconButtonClicked:(id)sender{

    NSString *path = [[NSBundle mainBundle] pathForResource:@"NextRevIt" ofType:@"mp3"];
    self.audioPlayer = [[AVAudioPlayer alloc ] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [audioPlayer play];


}

-(IBAction)musicoffButtonClicked:(id)sender{

    [audioPlayer stop];

}
+1  A: 

You need to release the audio player when you are done with it.

You should also use [audioPlayer prepareToPlay]; before play in your code.

Emil