This is the code related to panning/ scrubbable video. The current issue occurs when the second swipe gesture has a delta from the last position of the first swipe. In other words this code needs to take into account the current time of the video to prevent the skip.
```
func didSwipe(panGR: UIPanGestureRecognizer) {
let translation = panGR.translationInView(self.view)
var horizontalTranslation = Float(translation.x)
let durationInSeconds = Float(CMTimeGetSeconds(self.playerView.player.player.currentItem!.asset.duration))
// Using 275 as the limit for delta along x
let translationLimit: Float = 275
let minTranslation: Float = -1 * translationLimit
let maxTranslation: Float = translationLimit
if horizontalTranslation > maxTranslation {
horizontalTranslation = maxTranslation
}
if horizontalTranslation < minTranslation {
horizontalTranslation = minTranslation
}
let timeToSeekTo = normalize(horizontalTranslation , minDelta: minTranslation, maxDelta: maxTranslation, minDuration: 0, maxDuration: durationInSeconds)
print("horizontal translation \(horizontalTranslation) \n timeToSeekTo: \(timeToSeekTo)")
self.playerView.player.startScrubbing()
self.playerView.player.scrub(timeToSeekTo)
self.playerView.player.stopScrubbing()
}
func normalize(delta: Float, minDelta: Float, maxDelta: Float, minDuration: Float, maxDuration: Float) -> Float {
let result = ((delta - minDelta) * (maxDuration - minDuration) / (maxDelta - minDelta) + minDuration)
return result
}
```
I am setting the starting time to be exactly at half of the video length. This produces a good first swipe result in either direction. It has a noticeable skip on the second and subsequent swipes because it is not accounting for the current time of the video (i think).
Here's the code I wrote that employs the normalize function, and displays the current rate (and a Play icon that changes size according to the player rate:
The label setup, which can go anywhere, not just in the drawRect method:
And, the auto-adjusting Player icon size code:
The player icon is simply a character from the Apple Symbol font.