我有一個聲音循環,它是一個矩形按鈕,一旦用戶按下按鈕,聲音循環播放。我想要它,所以一旦用戶再次按下相同的按鈕,聲音停止播放。如何停止聲音 - 可可觸摸
這是代碼
- (IBAction)threeSound:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"wav"];
if (threeAudio) [threeAudio release];
NSError *error = nil;
threeAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error)
NSLog(@"%@",[error localizedDescription]);
threeAudio.numberOfLoops = -1;
threeAudio.delegate = self;
[threeAudio play];
}
感謝
此代碼還假定正在爲這兩個事件調用threeSound。 – slycrel 2011-04-27 00:07:12
他提到「再次按下相同的按鈕」,所以我認爲這是正確的。 – NWCoder 2011-04-27 00:10:47
對不起,我同意你的看法,只是爲了防止別人出現。 =) – slycrel 2011-04-27 06:29:27