我已经实现了一个递减计数器,它每秒播放点击声音,直到它的计时器失效。同时,我正在显示计数器值。
-(IBAction)start{
myTicker =[NSTimerscheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showactivity) userInfo:nil repeats:YES];
}
-(void)showactivity;{
int CurrentTime =[time.textintValue];
NSString *soundFilePath=[[NSBundlemainBundle] pathForResource:@"Click03" ofType:@"wav"];
NSURL *soundFileURL =[NSURLfileURLWithPath:soundFilePath];
AVAudioPlayer *player=[[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops =1;
[player play];
int newTime = CurrentTime-1;
time.text = [NSString stringWithFormat:@"%d",newTime];
if(newTime ==0){
[myTicker invalidate];
time.text = @"0";
}
}
计数器工作完美,但初始延迟很小;但它不播放声音,任何人都可以帮助我有效地实现这个概念,以最小的延迟等......