问题
I've searched Google and StackOverflow for two days and have yet to find a clear, concise answer.
My goal is to create a slider/progress bar that allows the user to scrub to a different part of the song, with two labels on either side, one showing the elapsed time and the other, the time left on the song.
I'm using DiracAudioPlayer, which also incorporates AVAudioPlayer functionality. Any help or direction to a tutorial is greatly appreciated.
回答1:
Not sure if this is an issue with doing the scrubbing or updating the time elapsed so I'll show what I think you can do for both.
To update the progress bar and time labels, Apple does the following in their example project avTouch
updateTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(updateCurrentTime) userInfo:player repeats:YES];
- (void)updateCurrentTime
{
currentTime.text = [NSString stringWithFormat:@"%d:%02d", (int)self.player.currentTime / 60, (int)p.currentTime % 60, nil];
progressBar.value = self.player.currentTime;
}
And then the seeking is simply done by setting the currentTime
- (IBAction)progressSliderMoved:(UISlider *)sender
{
player.currentTime = sender.value;
[self updateCurrentTimeForPlayer:player];
}
来源:https://stackoverflow.com/questions/13387469/create-a-uislider-progress-bar-and-timer-like-ipod-player-within-app