Convert from NStimeInterval to CMTime for sure

I use two players: MPMoviePlayerController and the other is AVPlayer . who is looking for MPMoviePlayerController , he sets the AVPlayer time. Everything is working fine. Converting the MPMoviePlayerController current time to CMTime , it rounds ex: (if mpplayer time is 11.80132, round to 11).

Without rounding, how can we set the time on AVPlayer ?

Code to get mpplayer time and send to AVPlayer class

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

Code in AVPlayer class and CMTime conversion 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 } 
+6
source share
1 answer

Try the following:

  CMTime seekingCM = CMTimeMakeWithSeconds(playbackTime, 1000000); 
+4
source

Source: https://habr.com/ru/post/951606/


All Articles