Play AVMutableComposition with AVPlayer?

前端 未结 1 602
暗喜
暗喜 2021-02-06 05:38

I\'m trying to get two videos to play sequentially. I\'ve tried AVQueuePlayer but there\'s a huge \"burp\" between the two clips. I need to them to play without interruption.

1条回答
  •  深忆病人
    2021-02-06 06:04

    Maybe you're using the wrong time insertion points and durations, both depends on actual video assets. I'd write something like this:

    CMTime insertionPoint = kCMTimeZero;
    NSError * error = nil;
    composition = [AVMutableComposition composition];
    asset = /* obtain asset #1 */
    if (![composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) 
                              ofAsset:asset 
                               atTime:insertionPoint 
                                error:&error]) 
    {
        NSLog(@"error: %@",error);
    }
    insertionPoint = CMTimeAdd(insertionPoint, asset.duration);
    
    asset = /* obtain asset #2 */
    if (![composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) 
                              ofAsset:asset 
                               atTime:insertionPoint 
                                error:&error]) 
    {
        NSLog(@"error: %@",error);
    }
    ...
    /* playback stuff */
    

    0 讨论(0)
提交回复
热议问题