title: Achieve smooth video scrubbing with AVPlayer
body: <p>I am trying to achieve smooth video scrubbing with <code>AVPlayer</code> through <code>UISlider</code> I have searched and it seems Apple has a <a href="https://developer.apple.com/library/content/qa/qa1820/_index.html#//apple_ref/doc/uid/DTS40016828" rel="noreferrer">Technical Q&amp;A</a> and explained how to achieve this, but my problem is how should I use this method and change player current time with a UISlider:
  <code>stopPlayingAndSeekSmoothlyToTime(newChaseTime:CMTime)</code></p>
  
  <p>Here is my code :</p>
  
  <pre><code>//Play Intro Movie
  let videoURL = Bundle.main.url(forResource: "intro", withExtension: "mp4")
  player = AVPlayer(url:videoURL!)
  let playerLayer = AVPlayerLayer(player: player)
  playerLayer.frame = self.view.frame
  view.layer.addSublayer(playerLayer)
  //videoPlayer.play()
  
  
  view.addSubview(slider)
  slider.maximumValue = 0
  slider.maximumValue = Float(CMTimeGetSeconds((player.currentItem?.asset.duration)!))
  </code></pre>
  
  <p>Here is Apple sample code :</p>
  
  <pre><code>func stopPlayingAndSeekSmoothlyToTime(newChaseTime:CMTime)
      {
          player.pause()
  
          if CMTimeCompare(newChaseTime, chaseTime) != 0
          {
              chaseTime = newChaseTime;
  
              if !isSeekInProgress
              {
                  trySeekToChaseTime()
              }
          }
      }
  
  
  
  
      func trySeekToChaseTime()
      {
          if playerCurrentItemStatus == .unknown
          {
              // wait until item becomes ready (KVO player.currentItem.status)
          }
          else if playerCurrentItemStatus == .readyToPlay
          {
              actuallySeekToTime()
          }
      }
  
  
      func actuallySeekToTime()
      {
          isSeekInProgress = true
          let seekTimeInProgress = chaseTime
          player.seek(to: seekTimeInProgress, toleranceBefore: kCMTimeZero,
                            toleranceAfter: kCMTimeZero, completionHandler:
              { (isFinished:Bool) -&gt; Void in
  
                  if CMTimeCompare(seekTimeInProgress, self.chaseTime) == 0
                  {
                      self.isSeekInProgress = false
                  }
                  else
                  {
                      self.trySeekToChaseTime()
                  }
          })
      }
  </code></pre>