Using AVPlayer for the iPhone, SeekToTime only ever restarts the video for me
I am trying to get a fairly short video (0.05 seconds) to play from 0.02 seconds. I use the code below:
CMTime tolerance = CMTimeMake(开发者_StackOverflow0,1);
CMTime replayBeginTime = CMTimeMake(1, 50);
[player seekToTime: replayBeginTime toleranceBefore: tolerance toleranceAfter: tolerance];
[player play];
Where player is an AVPlayer*. The video plays fine from start to finish and then i hit a button to go back to roughly the half way point and it should play from there, but every time it just restarts the video.
I'm not a 100% sure I'm using CMTimeMake correctly.
Any help figuring out what I'm doing wrong would be much appreciated.
You are creating a CMTime with a value of 1/50 = 0.02, so you are using CMTimeMake correctly. But I think maybe you should use CMTimeMakeWithSeconds instead. Because CMTimeMake can only take an integer value of seconds, while CMTimeMakeWithSeconds can take a float. You should use it like this.
CMTime newTime = CMTimeMakeWithSeconds(0.2, 1);
[player seekToTime:newTime];
Good luck.
精彩评论