views:

403

answers:

2
-(IBAction)musiconButtonClicked:(id)sender{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"NextRevIt" ofType:@"mp3"];
    AVAudioPlayer* audioPlayer = [[AVAudioPlayer alloc ] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [audioPlayer play];
}


-(IBAction)musicoffButtonClicked:(id)sender{
    [audioPlayer stop]; <----says this is undeclared?
}

I can get the audio to play fine, but how do i make a button that stops the audio?

A: 

Put this in your interface block in the .h.

AVAudioPlayer* audioPlayer;

You will need to check for an instance and release it as well.

Daniel A. White
A: 

You have declared AVAudioPlayer* audioPlayer as a method local variable. Change the scope of that variable to class level. Follow Daniel A. White's suggestion

Mihir Mathuria