IOS开发视频播放UIslider问题

mpmovieplayercontroller.currentPlaybackTime;设置视频seek指定秒播放,比如170秒,拖条用的时uislider,滑块经常被拖... mpmovieplayercontroller. currentPlaybackTime;设置视频seek指定秒播放,比如170秒,
拖条用的时 uislider,滑块经常被 拖 回去一点,很不爽!,到底什么问题?是不是bug?

打印研究发现给currentPlaybackTime设置时间,会回退几秒
为什么经常会 回退 几秒开始播放?设置170秒,回退164,167,163,或169,回退几秒开始播放,bug?
一开始以为网络问题,可是视频完成加载完了,也会有这个问题!

10次一般有5次这样的情况! 有人遇到吗?
展开
 我来答
  • 你的回答被采纳后将获得:
  • 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏100(财富值+成长值)
己学好4
推荐于2016-11-16 · TA获得超过1.5万个赞
知道大有可为答主
回答量:1.1万
采纳率:91%
帮助的人:5193万
展开全部
这有一个例子:
iPhone – Add an UISlider For AVAudioPlayer
We can use AVAudioPlayer to play music. Now i want to add an UISlider as the music progress bar and user can fast skip the music.

Now i have a play button in the view and when user click it, i will play the music file as well as the following method.

* playButtonClicked – Run when the play button is clicked
* updateSlider – Run in 1 second interval to update the UISlider
* sliderChange – Fast skip the music when user scroll the UISlider

Here comes the code - (IBAction)playButtonClicked:(id)sender {

// Read the file from resource folder and set it in the avAudioPlayer

NSURL *fileUrl = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"musicFile" ofType:@"caf"]];

avAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileUrl error:nil];

[avAudioPlayer setDelegate:self];

[avAudioPlayer setVolume:1.0];

// Set a timer which keep getting the current music time and update the UISlider in 1 sec interval

sliderTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateSlider) userInfo:nil repeats:YES];

// Set the maximum value of the UISlider

aSlider.maximumValue = avAudioplayer.duration;

// Set the valueChanged target

[aSlider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];

// Play the audio

[avAudioPlayer prepareToPlay];

[avAudioPlayer play];

}

- (void)updateSlider {

// Update the slider about the music time

aSlider.value = avAudioPlayer.currentTime;

}

- (IBAction)sliderChanged:(UISlider *)sender {

// Fast skip the music when user scroll the UISlider

[avAudioPlayer stop];

[avAudioPlayer setCurrentTime:aSlider.value];

[avAudioPlayer prepareToPlay];

[avAudioPlayer play];

}

// Stop the timer when the music is finished (Need to implement the AVAudioPlayerDelegate in the Controller header)

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {

// Music completed

if (flag) {

[sliderTimer invalidate];

}

}
复制代码
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式