タイマーが無効になるまで、毎秒クリック音を鳴らすダウンカウンターを実装しました。同時に、カウンター値を表示しています。
-(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";
}
}
カウンターは完全に機能しますが、初期遅延がわずかです。しかし、それはサウンドを再生しません。最小限の遅延などで、このコンセプトを効率的に実装するのを手伝ってくれる人はいますか...