Using MPMusicPlayerController, setting musicPlayer.currentPlaybackTime to seek but takes second to take effect

只谈情不闲聊 提交于 2019-12-06 06:13:33

问题


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

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

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.


回答1:


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.)




回答2:


I am having the same issue. I am simply delaying the NSTimer (for updating the slider) creation with another NSTimer (set to 1.5sec). This is happening when the slider is not pressed anymore.



来源:https://stackoverflow.com/questions/2379165/using-mpmusicplayercontroller-setting-musicplayer-currentplaybacktime-to-seek-b

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