我有一个声音循环,它是一个矩形按钮,一旦用户按下按钮,声音循环播放。我想要它,所以一旦用户再次按下相同的按钮,声音停止播放。如何停止声音 - 可可触摸
这是代码
- (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