Using MPMusicPlayerController, set musicPlayer.currentPlaybackTime to search, but takes second place to take effect

I have a UISlider acting like a scrubber. When dragging my thumb, I do the following:

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

It works great, the music is looking forward. After releasing the thumb, I restart NSTimer to send time updates to synchronize UISlider. The problem is that when you release your thumb, the first few callbacks contain the previous time value. This causes the thumb to return to its original position before returning to a new value. Very unsightly.

Does anyone have experience with this behavior and a way to fix it? I can provide a sample project if you want this to demonstrate this anomaly.

+4
source share
1 answer

Perhaps this is because there is already decoded data at the beginning of the buffer. You are looking for a minute ahead, but for a few milliseconds of audio in the buffer, and when these buckets are playing, the player reports his position in the file as current. Only then will there be new buckets from the updated position, and the marker will begin to behave. (Just a theory.)

Could you just filter the intermediate data manually? You know how much you jumped with the slider, so maybe you could save the new position in a variable and ignore updates from the player until they conveniently get closer to the new position of the slider. (Hope this makes sense.)

+1
source

Source: https://habr.com/ru/post/1303117/


All Articles