我有一個內置鋼琴的應用程序。按下時每個按鍵(Button1)開始播放音符,當用戶提起手指時,我希望音符停止播放。會發生什麼情況是,當停止功能設置爲按鍵(Button1)上的內側時,音頻不會停止播放。如果我改變從鋼琴鍵(按鈕1)的行動,以不同的按鈕(Button2的)停止播放,因爲它應該,如果我按下按鈕2AVAudioPlayer不停止玩Touch Up Inside
.H
#import <AVFoundation/AVAudioPlayer.h>
@interface FifthViewController : UIViewController <AVAudioPlayerDelegate> {
AVAudioPlayer *theNote;
}
.M
#import <AVFoundation/AVAudioPlayer.h>
#import <AVFoundation/AVFoundation.h>
//White
-(IBAction)note1w:(id)sender { //Touch Down
[self whiteKey:self];
[self downKey:self];
NSString *path = [[NSBundle mainBundle] pathForResource:@"white1" ofType:@"aif"];
theNote = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theNote.delegate = self;
theNote.currentTime = 0;
[theNote play];
}
-(IBAction)stopMusic { //Touch Up Inside - This is the action that I change from the Button1 (The Piano Key) to Button2 (A Reg UIButton) and it works.
[theNote stop];
}
我不明白爲什麼它不起作用。爲什麼不在停止之前嘗試暫停。如果仍然無法檢查** theNote **是否正確引用。我懷疑* - (IBAction)stopMusic *沒有被調用。 – TwilightSun