我有一个标签显示在同一屏幕上行走和音频播放器的经过时间。如何在播放音频时保持经过时间计时器的运行?一旦音频开始播放,定时器就会停止,即使音频停止也不会重新启动。
经过时间计时器 -
self.timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(eachSecond) userInfo:nil repeats:YES];
管理音频的计时器(在不同的班级中) -
-(NSString*)timeFormat:(float)value{
float minutes = floor(lroundf(value)/60);
float seconds = lroundf(value) - (minutes * 60);
NSInteger roundedSeconds = lroundf(seconds);
NSInteger roundedMinutes = lroundf(minutes);
NSString *time = [[NSString alloc] initWithFormat:@"%ld:%02ld", (long)roundedMinutes, (long)roundedSeconds];
return time;
}
-(void)setCurrentAudioTime:(float)value{
[self.backgroundMusicPlayer setCurrentTime:value];
}
-(NSTimeInterval)getCurrentAudioTime{
return [self.backgroundMusicPlayer currentTime];
}
-(float)getAudioDuration{
return [self.backgroundMusicPlayer duration];