我試圖以增加的頻率背靠背播放兩個音頻文件(點擊和克隆)。它按照第一秒的要求工作,然後聲音開始同時播放。任何想法我在這裏做錯了嗎?延遲播放AVAudioPlayer
static float clickClackDelay = 1.0;
- (void)runClickClackTimer {
clickURL = [[NSBundle mainBundle] URLForResource:@"click" withExtension:@"wav"];
clackURL = [[NSBundle mainBundle] URLForResource:@"clack" withExtension:@"wav"];
avClick = [[AVAudioPlayer alloc] initWithContentsOfURL:clickURL error:nil];
avClack = [[AVAudioPlayer alloc] initWithContentsOfURL:clackURL error:nil];
clickClack = [NSTimer scheduledTimerWithTimeInterval:clickClackDelay
target:self
selector:@selector(runClickClackTimer)
userInfo:nil
repeats:NO];
[avClick play];
sleep(clickClackDelay);
[avClack play];
sleep(clickClackDelay);
NSLog(@"Play sound every %.2f", clickClackDelay);
clickClackDelay -= 0.01;
}
輝煌。非常感謝。 – colindunn