I am having an issue with AVPlayer seek. Current code:
self.player?.seek(to: CMTime(seconds: Double(startSeconds), preferredTimescale: 600)
This works about 80% of the time. But sometimes it does't seek to the correct position and instead starts over at 0.0.
I attempted this way:
let time = CMTimeMake(value: Int64(startSeconds), timescale: 1)
self.player?.seek(to: time, toleranceBefore: .zero, toleranceAfter: .zero)
This works 100% of the time but it's very slow to seek.
What am I doing wrong here?
Default tolerance value is infinity(when not specified), but usually real difference from the requested value is about a second - this allows seek to be fast.
If in your case it is jumping to the file start, it's probably because your file was not correctly encoded.
If you cannot change source of your files, the best you can do is specifying tolerance more than zero, but not too big. Like ±1 sec. The less tolerance you have the longer seek would perform, so try to find some balance.