objective-c - 从 NStimeInterval 准确转换为 CMTime

标签 objective-c mpmovieplayercontroller avplayer nstimeinterval cmtime

我正在使用两个播放器,一个是 MPMoviePlayerController,另一个是 AVPlayer。每当寻找 MPMoviePlayerController 时,它都会将时间设置为 AVPlayer。一切正常。在将 MPMoviePlayerController 当前时间转换为 CMTime 时,它会四舍五入 ex:(如果 mpplayer 时间为 11.80132,则四舍五入为 11)。

不四舍五入,如何设置AVPlayer的时间?

获取mpplayer时间并发送到AVPlayer类的代码

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

AVPlayer 类中的代码并将时间转换为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
}

最佳答案

试试这个:

  CMTime seekingCM = CMTimeMakeWithSeconds(playbackTime, 1000000);

关于objective-c - 从 NStimeInterval 准确转换为 CMTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18203943/

相关文章:

ios - 更新核心数据中的对象值也是创建一个新对象

objective-c - Objective-C : How to create border effect around photos

iphone - 如何创建一个常量 NSDate

ios - Objective-C:如何从 UITableViewCell 播放视频?

swift - 如何修复此 'required condition is false: format.sampleRate == hwFormat.sampleRate' 错误?

ios - 如何在 iOS 中使用视频数据播放视频

ios - 在后台创建新的 AVPlayer 不起作用?

iphone - Objective-C/自动调整 subview 不起作用

iphone - MPMoviePlayerController - 如何判断正在播放的比特率?

ios - 如何让 MPMoviePlayerController 的 View 在非全屏时在旋转时调整大小