使用MPMusicPlayerController,将musicPlayer.currentPlaybackTime设置为seek但第二个生效 [英] Using MPMusicPlayerController, setting musicPlayer.currentPlaybackTime to seek but takes second to take effect

查看:149
本文介绍了使用MPMusicPlayerController,将musicPlayer.currentPlaybackTime设置为seek但第二个生效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UISlider充当洗涤器。当拖动拇指时,我执行以下操作:

I have a UISlider acting as the scrubber. As the thumb is dragged I execute the following:

- (void) _seekTo:(double)playbackTime {
     mPlayer.currentPlaybackTime = playbackTime;
}

这很好,音乐向前发展。释放拇指后,我重新启动NSTimer以发送时间更新以保持UISlider同步。问题是,在释放拇指时,前几个回调包含前一个时间值。这会导致拇指在返回新值之前跳回其原始位置。非常难看。

That works fine, music seeks forward. Upon releasing the thumb, I restart the NSTimer to send time updates to keep the UISlider in synch. Problem is, upon releasing the thumb, the first few call backs contain the previous time value. This causes the thumb to jump back to its original position before returning to the new value. Very unsightly.

任何人都有这种行为的经验和纠正方法吗?如果你想要证明这种异常,我可以提供一个示例项目。

Anyone have any experience with this behavior and a way to rectify? I can supply a sample project if you would like that demonstrates this anomaly.

推荐答案

也许是因为已经有解码数据了当你开始寻找时缓冲。你向前寻找一分钟,但缓冲区中有几毫秒的音频,当这些桶播放时,播放器将其在文件中的位置报告为当前。然后才从更新的位置开始新的桶,标记开始表现。 (只是一个理论。)

Maybe it’s because there are already decoded data in the buffer when you start seeking. You seek a minute forward, but there’s a few milliseconds of audio in the buffer, and when these buckets play, the player reports their position in the file as current. Only then come the new buckets from the updated position and the marker starts to behave. (Just a theory.)

你不能简单地手工过滤中间数据吗?你知道你使用滑块跳了多少,所以也许你可以将新位置存储到变量中并忽略来自玩家的更新,直到它们舒适地靠近新的滑块位置。 (希望这很有意义。)

Couldn’t you simply filter the intermediate data by hand? You know how much you have jumped using the slider, so maybe you could store the new position into a variable and ignore the updates from player until they get comfortably close to the new slider position. (Hope that makes sense.)

这篇关于使用MPMusicPlayerController,将musicPlayer.currentPlaybackTime设置为seek但第二个生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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