I am trying to achieve smooth video scrubbing with AVPlayer
through UISlider
I have searched and it seems Apple has a Technical Q&A and explain
Although I'm not using the same method as you do which is stopPlayingAndSeekSmoothlyToTime
, I thought I should help you with the seeking action of the player.
func sliderValueChanged() {
var timeToSeek = player.currentItem?.asset.duration.seconds
timeToSeek = timeToSeek * Double(slider.value)
player.seek(to: CMTimeMake(Int64(timeToSeek), 1))
}
Also you should set the slider.maximumValue
to 1. Hope this helps.
Note: Please don't forget to handle currentItem
optional value. If it is nil
you should set the value 0 for timeToSeek
variable.