要使用 CMTime 数据结构
CMTimeMake(a, b) a是当前播放的 第几帧,b表示每秒播放多少帧(fps)。 播放时间就是:a/b
CMTimeMakeWithSeconds(a, b) a是当前时间,b表示每秒播放的帧数(fps)。 即 timeScale。
CMTime算是一个对于time实际时间关于音视频处理的一个时间结构体。
获取当前视频的 timeScale。playerItem.asset.duration 获取的总时长,返回 CMTime结构,里面有timeScale。
First, get the timescale value and pass it to the CMTime struct. Second, use the seekToTime:toleranceBefore:toleranceAfter:completionHandler: method for more accurate seeking. For example, your code would look like:
- (IBAction)progressBarDraggindStop:(id)sender {
int32_t timeScale = self.audioPlayer.currentItem.asset.duration.timescale;
[self.audioPlayer seekToTime: CMTimeMakeWithSeconds(self.progressBar.value, timeScale)
toleranceBefore: kCMTimeZero
toleranceAfter: kCMTimeZero
completionHandler: ^(BOOL finished) {
[self.audioPlayer play];
}];
}
CMTime结构详解
本文介绍了CMTime数据结构的使用方法,包括如何通过CMTimeMake和CMTimeMakeWithSeconds创建时间结构体,以及如何利用这些结构体进行精确的时间定位。特别地,文章提供了使用CMTime进行视频播放进度调整的具体代码实例。
4189

被折叠的 条评论
为什么被折叠?



