【发布时间】:2011-03-08 21:16:42
【问题描述】:
我正在尝试使用 AVFoundation 框架创建一个带有很多按钮的音板“交互式采访”。音板已经完成,但我有一个问题,当我按下我的一个声音时,当我同时按下一个新的声音时它不会停止。如果按下新声音,是否有一种简单的方法可以停止以前的声音?我的代码是这样的
- (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”或其他任何内容。已经学习了拼写和术语!
标签: cocoa-touch cocoa avaudioplayer