Convert from NStimeInterval to CMTime accurately

9.5k views Asked by At

I am using two players one is MPMoviePlayerController and the other is AVPlayer. henever MPMoviePlayerController is seeked, it sets the time to AVPlayer. Everything is working fine. While converting MPMoviePlayerController current time to CMTime it is rounding off ex:(if mpplayer time is 11.80132 it is rounding to 11).

Without rounding off, how can we set the time to AVPlayer?

Code for getting mpplayer time and sending to AVPlayer class

[avplayerClass  setCurrentTime:[self.videoPlayer currentPlaybackTime]];
NSLog(@"CurrentTime:%f",[self.videoPlayer currentPlaybackTime]);//11.801345

Code in AVPlayer class and converting time to CMTime

-(void)setCurrentTime:(NSTimeInterval)seekTime
{
    CMTime seekingCM = CMTimeMake(seekTime, 1);
    [self.player seekToTime:seekingCM 
            toleranceBefore:kCMTimeZero 
             toleranceAfter:kCMTimePositiveInfinity];
    [self.player seekToTime:seekingCM];
    NSLog(@"Current time123ns%%%%%%:%f",CMTimeGetSeconds(seekingCM));//11
    NSLog(@"Current time123ns%%%%%%:%f",seekTime);//11.801345
}
1

There are 1 answers

0
Jenel Ejercito Myers On

Try this :

  CMTime seekingCM = CMTimeMakeWithSeconds(playbackTime, 1000000);