在Xcode中,我设置了播放音乐剪辑的按钮,播放时间为40秒。我的问题是,如何将UIProgressView链接到音乐播放?例如,如果歌曲播放到一半,进度条将显示该内容。
发布于 2013-05-13 14:30:53
如果您在类中定义了以下内容:
AVAudioPlayer *audioPlayer;
UIProgressView *progressView;
NSTimer *audioTimer;
在计时器上运行它似乎是可行的:
- (void)audioProgressUpdate
{
if (audioPlayer != nil && audioPlayer.duration > 0.0)
[progressView setProgress:(audioPlayer.currentTime / audioPlayer.duration)];
}
启动剪辑时,启动计时器(每十分之一秒运行一次):
[audioPlayer play];
audioTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(audioProgressUpdate) userInfo:nil repeats:YES];
当你停止剪辑时,停止计时器:
[audioTimer invalidate];
[audioPlayer stop];
https://stackoverflow.com/questions/16403458
复制相似问题