han*_*Dev 3 iphone objective-c nstimer avaudioplayer ios
我有一个倒数计时器,显示音轨上剩余的秒数.由于某种原因,倒计时不是以1秒的间隔计数,而是在第一次计数时为2秒,在下一次计数时为1秒.(它正在计算这种模式 - 它会跳2秒,然后一遍又一遍).
这是我的代码:
// display current time left on the track
- (void)updateTimeLeft {
NSTimeInterval timeLeft = self.player.duration - self.player.currentTime;
// update your UI with timeLeft
self.timeDisplay.text = [NSString stringWithFormat:@"%.2f", timeLeft / 60];
}
Run Code Online (Sandbox Code Playgroud)
这是我的NSTimer:
NSTimer * myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimeLeft) userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
试试这个
- (void)updateTimeLeft
{
NSTimeInterval timeLeft = self.player.duration - self.player.currentTime;
int min=timeLeft/60;
int sec = lroundf(timeLeft) % 60;
// update your UI with timeLeft
self. timeDisplay.text = [NSString stringWithFormat:@"%d minutes %d seconds", min,sec];
}
Run Code Online (Sandbox Code Playgroud)
只是一个想法