合并播放多段視頻
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 垒玲;第三段....
如果為多段陆馁,播放第一段時,點擊播放下一段的時候合愈,此時直接用下面代碼叮贩,然后監(jiān)控進度击狮,會發(fā)現(xiàn)播放并不是從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];