Achieve smooth video scrubbing with AVPlayer

前端 未结 4 1667
你的背包
你的背包 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 02:57

    try to add selectors to your slider like this at the begining:

    playerView.timeSlider.addTarget(self, action: #selector(PlayerViewController.timeSliderBeganTracking(_:)), for:.touchDown) // moved
            playerView.timeSlider.addTarget(self, action: #selector(PlayerViewController.timeSliderEndedTracking(_:)), for: .touchUpInside)
            playerView.timeSlider.addTarget(self, action: #selector(PlayerViewController.timeSliderEndedTracking(_:)), for: .touchUpOutside )
    

    then in timeSliderBeganTracking set isSeekInProgress to true and pause your player and invalidate timers and remove observers if you have any

    then in timeSliderEndedTracking seek to current time like this :

    let currentSeconds = Float64(self.playerView.timeSlider.value) container.player.seek(to: CMTimeMakeWithSeconds(currentSeconds, 100)) then add the observers and timers back and at the end set isSeekInProgress to false

    HERE you can find a complete sample of creating a custom videoPlayer

提交回复
热议问题