美文网首页
iOS AVPlayer合并视频播放时,seekToTime后

iOS AVPlayer合并视频播放时,seekToTime后

作者: 红叶潇潇 | 来源:发表于2023-10-18 09:59 被阅读0次

合并播放多段视频

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];

相关文章

网友评论

      本文标题:iOS AVPlayer合并视频播放时,seekToTime后

      本文链接:https://www.haomeiwen.com/subject/zmtcidtx.html