Achieve smooth video scrubbing with AVPlayer

前端 未结 4 1631
你的背包
你的背包 2021-01-02 02:30

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

4条回答
  •  别那么骄傲
    2021-01-02 03:13

    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.

提交回复
热议问题