Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert from NStimeInterval to CMTime accurately

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
}
like image 470
kmReddy Avatar asked Aug 13 '13 08:08

kmReddy


1 Answers

Try this :

  CMTime seekingCM = CMTimeMakeWithSeconds(playbackTime, 1000000);
like image 120
Jenel Ejercito Myers Avatar answered Nov 18 '22 06:11

Jenel Ejercito Myers