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 に答える