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

我可以让音频正常播放,但是如何制作一个停止音频的按钮?

4

2 回答 2

4

把它放在你的interface块中.h

AVAudioPlayer* audioPlayer;

您将需要检查实例并释放它。

于 2010-02-04T19:43:04.637 回答
0

您已声明AVAudioPlayer* audioPlayer为方法局部变量。将该变量的范围更改为类级别。遵循Daniel A. White 的建议

于 2010-02-04T19:48:50.327 回答