NextRev
NextRev

Reputation: 1711

MP3 playback and stop issue?

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];

}

Upvotes: 0

Views: 207

Answers (1)

Emil
Emil

Reputation: 7256

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

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

Upvotes: 1

Related Questions