2012-03-20 44 views

回答

4

我用一个定时器来检查当前时间,然后每半秒更新我的进度条,就像这样:

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]; 
} 

希望这有助于!

+0

顺便说一句我正在使用AVAudioPlayer类来播放我的音频。 – 2012-03-20 22:46:23