我为AVPlayer创建了一个用于擦除器UISlider的方法。在播放歌曲(第一次播放)时它工作正常。当我点击UISlider(scrubber)改变歌曲位置然后歌曲计时器(audioPlayerTimerLabel)显示正确的值而歌曲也改变它的位置并且歌曲播放正常, 但是UISlider不能正常工作。例如,当我触摸它并向前移动它会很好,但是当我释放(释放)它时,它会回到错误的位置。 (歌曲+歌曲计时器工作正常) 任何建议都会很棒。提前致谢 !!!..... 我的代码:
- (IBAction)audioPlayerValueChanged:(UISlider *)aSlider {
[player seekToTime:CMTimeMakeWithSeconds(duration_seconds*aSlider.value, 1)];
}
- (void)updateTime:(NSTimer *)timer {
currentTime = CMTimeGetSeconds(playerItem.currentTime);
duration = CMTimeGetSeconds(playerItem.duration);
self.audioSliderBar.continuous = YES;
[self.audioSliderBar setValue:(currentTime/duration)];
float minutes = floor(currentTime/60);
seconds =currentTime - (minutes * 60);
float duration_minutes = floor(duration/60);
duration_seconds =
duration - (duration_minutes * 60);
NSString *timeInfoString = [[NSString alloc]
initWithFormat:@"%0.0f:%0.0f",
minutes, seconds ];//],
self.audioCurrentTimeLabel.text = timeInfoString;
}
-(IBAction)touchDown:(id)sender {
[player pause];
[nsTimer invalidate];
}
-(IBAction)touchUp:(id)sender {
[player play];
nsTimer2=[NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
}