Using seconds in AVPlayer seekToTime

guardabrazo picture guardabrazo · Mar 26, 2014 · Viewed 14.2k times · Source

this should be a simple one. I have an AVPlayer playing a video file and I want to be able to jump to a specific time but I'm having some trouble understanding how CMTime works.

I need to specify the time in seconds. For example: if I wanted to jump to second 10.8 I'd like to do something like this:

[self.avPlayer.currentItem seekToTime:CMTimeMakeWithSeconds(10.8, 1];

But I'm not getting the result I want.

Answer

amergin picture amergin · Mar 27, 2014

http://warrenmoore.net/understanding-cmtime

Might give you a clearer idea of CMTime.

If you changed your line to read...

[self.avPlayer.currentItem seekToTime:CMTimeMakeWithSeconds(10.8, 60000)];

You might get better results. The 60000 is how many items make up a single second. If you use 1 for this value then you can only jump to a single place per second - by putting 60000 you are giving yourself 60000 places between second 10 and second 11.