When using AVPlayer method – SeekToTime, you might find there’s a problem: the position of seeking time is not correct, or, in other word, it’s at the exact time slot we want.
Especially, when you do development on multimedia App with subtitles, this will be a big problem cause users might expect that the people speaking tone can match the subtitle. Or they will be mad at you.
I have tried some ways to achieve this goal – precisely put my time cursor on the correct position. But I didn’t get a good result for that.
For example, I had tried this.
[self.avPlayer seekToTime: CMTimeMakeWithSeconds(musicTime, 600) toleranceBefore: kCMTimeZero toleranceAfter: kCMTimeZero];
Cause I wanna search specific music time for next jump. But the result would get extra .x seconds. After searching and studying, I finally find the answer. You need to get the time scale of current playing asset. That’s the most important thing.
// Get current asset time scale first. int32_t currentAssetTimeScale = self.avPlayer.currentItem.asset.duration.timescale; CMTime exactTime = CMTimeMake(musicTime, timeScale); [self.player seekToTime:exactTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
After doing that, then you can seek precise time you want.