在应用程序中创建UISlider进度栏和计时器(如iPod Player) [英] Create a UISlider progress bar and timer (like iPod player) within app

查看:127
本文介绍了在应用程序中创建UISlider进度栏和计时器(如iPod Player)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了Google和StackOverflow两天了,但是还没有找到清晰,简洁的答案.

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.

我正在使用DiracAudioPlayer,它还集成了AVAudioPlayer功能.对于教程的任何帮助或指导,我们将不胜感激.

I'm using DiracAudioPlayer, which also incorporates AVAudioPlayer functionality. Any help or direction to a tutorial is greatly appreciated.

推荐答案

不确定执行清理或更新经过的时间是否存在问题,因此我将展示我认为两者都可以做的事情.

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.

要更新进度条和时间标签,Apple在其示例项目

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;
}

然后只需设置currentTime即可完成搜索

And then the seeking is simply done by setting the currentTime

- (IBAction)progressSliderMoved:(UISlider *)sender
{
    player.currentTime = sender.value;
    [self updateCurrentTimeForPlayer:player];
}

这篇关于在应用程序中创建UISlider进度栏和计时器(如iPod Player)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆