In my app playing audiofile for that i want to show UIProgressBar on the UIToolbar for audiofile playing progress. Anyone can help me how to code for it.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I use a timer to check the current duration, and then update my progress bar every half second, like so:
tmrCounter = [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(updateElapsedTime) userInfo:nil repeats:YES];
-(void)updateElapsedTime{
if (player) {
[prgIndicator setProgress:[player currentTime] / [player duration]];
[lblTime setText:[NSString stringWithFormat:@"%@", [self formatTime:[player currentTime]]]];
}
}
-(NSString*)formatTime:(float)time{
int minutes = time / 60;
int seconds = (int)time % 60;
return [NSString stringWithFormat:@"%@%d:%@%d", minutes / 10 ? [NSString stringWithFormat:@"%d", minutes / 10] : @"", minutes % 10, [NSString stringWithFormat:@"%d", seconds / 10], seconds % 10];
}
Hope this helps!