Seeking accurately, as opposed to two seconds short, in AVPlayer

北战南征 提交于 2019-12-04 23:45:49

I misunderstood the tolerances and had them backwards.

Each tolerance is how far in that direction AVPlayer is allowed to move away from the requested time. So, passing positive infinity for toleranceBefore is saying “you can be as early as you want”, and passing zero for toleranceAfter is saying “just don't be late” (which would be a neat trick when seeking to the end).

Thus, the solution is to switch the values:

[self.player seekToTime:self.player.currentItem.duration
        toleranceBefore:kCMTimeZero
         toleranceAfter:kCMTimePositiveInfinity];

Or, in English: “Don't be early, but you can be as late as you want.”

prajna

Here's a swift version of the answer by @Peter Hosey:

self.player.seekToTime(self.player.currentItem.duration,
            toleranceBefore: kCMTimeZero,
            toleranceAfter: kCMTimePositiveInfinity)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!