Я пытаюсь создать простой AVAsset, содержащий три фильма, которые будут воспроизводиться один за другим, но на практике я вижу только первый воспроизводимый.
В следующем коде вызывается movieAssetWithBlock
классом клиента, чтобы получить AVAsset, который впоследствии проигрывается клиентом.
На основе ресурса, созданного ниже, я бы ожидал, что video1.mp4 будет проигрываться в течение 5 секунд, а затем video2.mp4 в течение 5с, а затем video3.mp4 (хотя это не так ...).
typedef void(^MovieAssetBlock)(AVAsset*);
+ (void) createComposition:(AVMutableComposition*)composition forResource:(NSString*)fileName nextClipStartTime:(CMTime*)nextClipStartTime
{
NSString *itemPath = [[NSBundle mainBundle] pathForResource:[fileName stringByDeletingPathExtension] ofType:[fileName pathExtension]];
NSURL *url = [[[NSURL alloc] initFileURLWithPath:itemPath] autorelease];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:options];
CMTimeRange timeRangeInAsset = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(5, 1)); // For test - only 5 sec
AVAssetTrack *clipVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[compositionVideoTrack insertTimeRange:timeRangeInAsset ofTrack:clipVideoTrack atTime:*nextClipStartTime error:nil];
assert(insertOk);
DLog(@"Inserting asset time range [Start: %lld Duration: %lld] at time [%lld]",
timeRangeInAsset.start.value, timeRangeInAsset.duration.value,
(*nextClipStartTime).value);
*nextClipStartTime = CMTimeAdd(*nextClipStartTime, timeRangeInAsset.duration);
}
+ (void) movieAssetWithBlock:(MovieAssetBlock)block
{
CMTime nextClipStartTime = kCMTimeZero;
AVMutableComposition *composition = [AVMutableComposition composition];
[self createComposition:composition forResource:@"video1.mp4" nextClipStartTime:&nextClipStartTime];
[self createComposition:composition forResource:@"video2.mp4" nextClipStartTime:&nextClipStartTime];
[self createComposition:composition forResource:@"video3.mp4" nextClipStartTime:&nextClipStartTime];
block(composition);
}