声音停止播放

时间:2011-11-11 13:19:36

标签: iphone ios4 audio ios5 avaudioplayer

  

可能重复:
  iPhone - Sound overlapping with multiple button presses

- (void)playOnce:(NSString *)aSound {

    NSString *path = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"];
    AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [theAudio setDelegate: self];
    [theAudio setNumberOfLoops:0];
    [theAudio setVolume:1.0];
    [theAudio play];



}

- (void)playLooped:(NSString *)aSound {

    NSString *path = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"];
    AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [theAudio setDelegate: self];
    // loop indefinitely
    [theAudio setNumberOfLoops:-1];
    [theAudio setVolume:1.0];
    [theAudio play];
    [theAudio release];

}

当我按下另一个按钮时,如何让声音停止播放?

0 个答案:

没有答案