我想制作一个播放声音文件的循环(非常短暂的哔哔声)并等待延迟时间然后重复,此循环一直运行直到我点击暂停按钮并且可以通过滑块按钮更改等待时间延迟循环正在运行。
- (void)playSound
{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Metronome-Sound.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer play];
}
- (IBAction)playSelected:(UIButton *)sender
{
if (stateOfMetronome == 0){
stateOfMetronome = 1;
while (stateOfMetronome == 1){
[self playSound];
[NSThread sleepForTimeInterval:delay];
}
}
}
- (IBAction)pauseSeleted:(UIButton *)sender
{
if (stateOfMetronome == 1){
stateOfMetronome = 0;
[audioPlayer pause];
}
}