-1
我正在尝试使用AVFoundation框架创建一个带有很多按钮的“互动式采访”音板。音板完成,但我有一个问题,当我按下我的一个声音时,它不会停止,当我同时按下一个新的。如果按下新的声音,是否有简单的方法来停止以前的声音?我的代码看起来像这样如何使用AVAudioPlayer发布声音?
- (IBAction)playSound0 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[theAudio play];
}
- (IBAction)playSound1 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"chillwhatup" ofType:@"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[theAudio play];
}
- (IBAction)playSound2 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"gethighorgetlow" ofType:@"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[theAudio play];
}
- (IBAction)playSound3 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"icamefromthere" ofType:@"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[theAudio play];
}
- (IBAction)playSound4 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"idoeverythinggood" ofType:@"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[theAudio play];
}
这与Xcode无关。此外,它拼写“Xcode”,而不是**“XCODE”,“xCode”,“XCode”或其他任何东西。已经了解您的拼写和术语! – 2014-01-01 12:08:19