你好 我在視圖中有16個聲音。而他們循環等我想要一個矩形按鈕,你可以點擊它的所有聲音停止。 這裏是我用於聲音的一個代碼,它同樣爲休息。#立即停止所有聲音?
- (IBAction)twoSound:(id)sender; {
if (twoAudio && twoAudio.playing) {
[twoAudio stop];
[twoAudio release];
twoAudio = nil;
return;
}
NSString *path = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"wav"];
if (twoAudio) [twoAudio release];
NSError *error = nil;
twoAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error)
NSLog(@"%@",[error localizedDescription]);
twoAudio.delegate = self;
[twoAudio play];
}
我試圖
-(IBAction)goStop:(id)sender; {
[oneAudio, twoAudio, threeAudio, fourAudio, fiveAudio, sixAudio, sevenAudio, eightAudio, nineAudio, tenAudio, elevenAudio, twelveAudio, thirteenAudio, fourteenAudio, fifthteenAudio, sixteenAudio stop];
}
但沒有工作。
謝謝
讓你希望Objective-C有ActionScript的'stopAllSounds()'或其他東西:) – BoltClock 2011-04-30 23:57:26
大聲笑是啊,我希望!我想我嘗試了懶惰的方式..和史蒂夫工作可能不喜歡懶惰的人:( – user731501 2011-05-01 00:01:28