的ProgressView没有更新。通过从其他帖子阅读我已经使用更新方法来更新在每个时间间隔。UIProgressView不会更新音频播放器?而播放歌曲
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"Fix you_Coldplay" ofType:@"mp3" inDirectory:@"Coldplay"];
NSLog(@"%@",filePath);
NSURL *url = [NSURL fileURLWithPath:filePath];
NSLog(@"%@",url);
musicPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
[musicPlayer prepareToPlay];
[trackProgress setProgress:0.0];
}
我有一个播放按钮,它也被用来调用updateTime:方法。
- (IBAction)playButton:(id)sender {
[musicPlayer play];
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
NSTimeInterval interval = musicPlayer.currentTime/musicPlayer.duration;
NSLog(@"%f",interval);
}
的更新时间:方法
-(void)updateTime:(NSTimer *)timer {
trackProgress.progress = (musicPlayer.currentTime/musicPlayer.duration);
}
我很新的节目,甚至堆栈溢出。这是我发布的第一个问题。请帮助我,并提前致谢。
这不起作用上更新进度视图。当我弹奏时,进度条从零位移动到小前进位置,但在此之后,它再次成为停滞状态 – Finch
您可以检查您获得此分区的最终浮点值:(musicPlayer.currentTime/musicPlayer.duration)。 –
当我没有插入在一个注册NSLog的语句:方法,所述浮子值从0.0开始和最终的浮点值是0.999081。但在结束曲目结束时,当我检查音乐停止播放时是0.002723,然后突然跳到0.993965,结束于0.999081。 – Finch