循环可可触摸中的声音

问题描述:

我有一个矩形按钮,当用户按下它一次。声音播放 但我想要它,所以当用户双击按钮时,声音连续循环直到用户决定按下停止声音。 这是播放声音的代码。循环可可触摸中的声音

- (IBAction)oneSound:(id)sender; { 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"wav"]; 
    if (theAudio) [theAudio release]; 
    NSError *error = nil; 
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error]; 
    if (error) 
     NSLog(@"%@",[error localizedDescription]); 
    theAudio.delegate = self; 
    [theAudio play]; 
} 

谢谢!

+0

这与Xcode没有任何关系(并且它是_is_“Xcode”,而不是“xCode”)。我会为你重新设计。 – 2011-04-17 18:06:06

+1

很抱歉!史蒂夫乔布斯会杀了我,如果他看到了这一点。 – LAA 2011-04-17 18:49:10

加入这一行:

theAudio.numberOfLoops = -1; 

的负值使得玩家永远循环下去,直到它停止。

+0

好吧,我怎么控制声音的速度和节奏一样,因为声音播放速度非常快 – LAA 2011-04-17 18:43:52

+0

在wave文件末尾添加一些沉默以使声音重复变慢。 (并且不要忘记标记安妮的答案被接受) – Till 2011-04-17 18:59:27

+0

好的,谢谢你们 – LAA 2011-04-17 19:37:57