【发布时间】:2014-04-03 13:31:01
【问题描述】:
我正在开发的音频播放器上有两个标签。一个是经过的时间,一个是歌曲的持续时间,就像在 iTunes 中一样。
但是,当我玩时,时间会滞后。在 7 秒的歌曲中,经过的时间为“0:00”,持续时间为“-0:07”。然后,当我播放这首歌时,标签会先显示“0:01”和“-0:07”,然后再转到“0:01”和“-0:06”
这是我的设置方式。
-(NSString*)timeFormat:(float)value{
float minutes = lroundf((value)/60);
float seconds = lroundf((value) - (minutes * 60));
int roundedSeconds = (seconds);
int roundedMinutes = (minutes);
NSString *time = [[NSString alloc]
initWithFormat:@"%d:%02d",
roundedMinutes, roundedSeconds];
return time;
- (void)updateTime:(NSTimer *)timer {
self.timeElapsed.text = [NSString stringWithFormat:@"%@",
[self timeFormat:[player currentTime]]];
self.duration.text = [NSString stringWithFormat:@"-%@", [self timeFormat: player.duration - player.currentTime]];
播放按钮会触发这个计时器:
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01
target:self
selector:@selector(updateTime:)
userInfo:nil
repeats:YES];
有什么想法吗?
谢谢。
【问题讨论】:
标签: ios objective-c cocoa-touch audio nstimer