2011-04-17 66 views
0

我有一個矩形按鈕,當用戶按下它一次。聲音播放 但我想要它,所以當用戶雙擊按鈕時,聲音連續循環直到用戶決定按下停止聲音。 這是播放聲音的代碼。循環可可觸摸中的聲音

- (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

回答

1

加入這一行:

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