iOS AVPlayer合并视频播放时,seekToTime后currentTime获取时间异常

合并播放多段视频

self.composition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *videoTrack = [self.composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

//可以加多个
AVAsset *asset = [AVAsset assetWithURL:@"视频地址"];
NSError *error = nil;
[videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration)
                                ofTrack:[[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
                                 atTime:currentTime
                                  error:&error];

假如:第一段105s;第二段80s ;第三段....
如果为多段,播放第一段时,点击播放下一段的时候,此时直接用下面代码,然后监控进度,会发现播放并不是从105开始,我这边是从100开始的

[self.movePlayer.player seekToTime:CMTimeMake(105, 1)];

可以改用如下方法就可以了

CMTime time = CMTimeMakeWithSeconds(105, self.player.currentItem.asset.duration.timescale);
[self.player seekToTime:time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容