-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