2011-03-08 51 views
-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]; 

} 
+0

这与Xcode无关。此外,它拼写“Xcode”,而不是**“XCODE”,“xCode”,“XCode”或其他任何东西。已经了解您的拼写和术语! – 2014-01-01 12:08:19

回答

0

我只想有我的课跟踪上次启动的声音,在此之前我开始玩一个新的声音,停止以前的一个,如果它仍然在播放。

AVAudioPlayer有停止方法停止声音和方法,看它是否被打。

+0

谢谢,但那并不能告诉我很多:( – 2011-03-08 22:21:06

相关问题