播放音频时在 UIToolbar 上有一个 UISlider ProgressBar 希望 UISlider ProgressBar 显示音频文件的持续时间和音频文件的当前时间。
- (void)playAction:(id)sender
{
if([player isPlaying])
{
[sender setImage:[UIImage imageNamed:@"1play.png"] forState:UIControlStateSelected];
[player pause];
//[self pauseTimer];
}else{
[sender setImage:[UIImage imageNamed:@"audiopause.png"] forState:UIControlStateNormal];
[player play];
//[self resumeTimer];
}
[self updateProgressBar:timer];
}
- (void)updateProgressBar:(NSTimer *)timer
{
NSTimeInterval playTime = [self.player currentTime];
NSTimeInterval duration = [self.player duration];
float progress = playTime/duration;
[_progressBar setProgress:progress];
}
但它不起作用。
感谢帮助。