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

StackOverflow https://stackoverflow.com/questions/2379165

Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top