Create a UISlider progress bar and timer (like iPod player) within app

余生长醉 提交于 2019-12-25 18:34:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!