首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从NStimeInterval到CMTime的精确转换

从NStimeInterval到CMTime的精确转换
EN

Stack Overflow用户
提问于 2013-08-13 16:14:37
回答 1查看 8.9K关注 0票数 8

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

如果不进行四舍五入,如何将时间设置为AVPlayer

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

代码语言:javascript
复制
[avplayerClass  setCurrentTime:[self.videoPlayer currentPlaybackTime]];
NSLog(@"CurrentTime:%f",[self.videoPlayer currentPlaybackTime]);//11.801345

AVPlayer类中的代码并将时间转换为CMTime

代码语言:javascript
复制
-(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
}
EN

回答 1

Stack Overflow用户

发布于 2016-07-19 04:47:11

试试这个:

代码语言:javascript
复制
  CMTime seekingCM = CMTimeMakeWithSeconds(playbackTime, 1000000);
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18203943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档