gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 03:38:00 24 4
gpt4 key购买 nike

我正在使用两个播放器,一个是 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com