我想将录制的声音循环 3 次,但想要在循环之间保持一秒钟的静音,我该怎么做?我的 play_button 代码:
-(IBAction) play_button_pressed{
AVAudioPlayer * avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error];
[avPlayer setNumberOfLoops: 2];
[avPlayer play];
}
1)我可以在这个方法中添加什么来增加这一秒的沉默吗?
2)如果没有,有没有办法在实际录音中增加一秒钟的沉默?
编辑:谢谢;我得到了一个解决方案,它可以在 2 秒的暂停中重复一次声音;它不会无限循环,你能告诉我我错过了什么吗?
-(IBAction) play_button_pressed{
AVAudioPlayer * avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error];
//[avPlayer setNumberOfLoops: 2];
avPlayer.delegate = self;
[avPlayer prepareToPlay];
[avPlayer play];
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)avPlayer successfully:(BOOL)flag
{
NSLog(@"audioPlayerDidFinishPlaying");
tm = [NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(waitedtoplay)
userInfo:nil
repeats:NO];
}
-(void) waitedtoplay
{
AVAudioPlayer * avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error];
[tm invalidate];
[avPlayer prepareToPlay];
[avPlayer play];
NSLog(@"waitedtoplay");
}