Question

-(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?

Was it helpful?

Solution

Put this in your interface block in the .h.

AVAudioPlayer* audioPlayer;

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top