播放第二个声音时,iPhone声音不会停止

时间:2011-11-11 22:04:28

标签: iphone ios4 audio

  

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

我的代码有声音按钮,当按下它时会播放声音,但是当按下另一个声音时,声音会重叠。我已经尝试了一些东西,但没有任何帮助。如何停止重叠播放的声音?

(void) playLooped: (NSString * ) aSound { 
    NSString * path = [[NSBundle mainBundle] pathForResource: aSound ofType: @"caf"];

    if([theAudio isPlaying])
    {
        [theAudio stop];
    }

    if (!theAudio) {
        theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath: path] error: NULL];
    } 
    [theAudio setDelegate: self];
    // loop indefinitely
    [theAudio setNumberOfLoops: -1];
    [theAudio setVolume: 1.0];
    [theAudio play];
}

0 个答案:

没有答案
相关问题