在我的播放音频文件的应用程序中,我想在UIToolbar上显示音频文件播放进度的UIProgressBar。任何人都可以帮助我如何为它编码。
发布于 2012-03-21 06:45:53
我使用计时器来检查当前的持续时间,然后每半秒更新一次进度条,如下所示:
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];
}希望这能有所帮助!
https://stackoverflow.com/questions/9796031
复制相似问题