MYSTERY ZILLION တွင် English သို့မဟုတ် Unicode ဖြင့်သာ အသုံးပြုခွင့်ရှိသည်။ ဇော်ဂျီ ၊ ဧရာ စသည်တို့ကို အသုံးပြုခွင့် မရှိ။ Unicode fonts များမှာ Mon3,Yunghkio, Myanamr3 စသည်များ အသုံးပြုနိုင်သည်။ Unicode Guide ကို ဒီမှာ Download ချပါ။ Zawgyi to Unicode Converter
Don't share ebook or software if nobody request. You can find free book websites on here. We are welcome for discussion or asking question instead.

AVAssetTrack Combine video not okay in iOS 7

edited March 2014 in iOS Devlopment

Hi everyone,

I can successfully combine 2 video into 1 in iOS 6. But I don't know what happen in iOS 7. I got array error like this.

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

This is part of the code I write. I have shown where error is, in the code. How should I do?

    NSMutableArray *array = [[NSMutableArray alloc]init ];
    for(int kk=0;kk < trackRecordingVideoName+1; kk++)
        [array addObject:[[self userPath] stringByAppendingPathComponent:[NSString stringWithFormat:@%@%d.mp4",recordingVideoName,kk]]];
        NSLog(@%d is added,kk);
    videoPathArray= [[NSArray alloc]initWithArray:array];
    [videoPathArray retain];
    AVMutableComposition *composition = [AVMutableComposition composition];
    AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
    CMTime startTime = kCMTimeZero;
    NSLog(@videoPathArray.count is %d,videoPathArray.count);
    for (NSInteger i=0; i < videoPathArray.count; i++) {
        NSLog(@For loop now is %d and name is %@",i,[videoPathArray objectAtIndex:i]);
        NSString *path = (NSString*)[videoPathArray objectAtIndex:i];
        NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
        AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
        [url release];
        AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];//This is the error

        if(i == 0)
            [compositionVideoTrack setPreferredTransform:videoTrack.preferredTransform];

        Boolean ok = [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [asset duration]) ofTrack:videoTrack atTime:startTime error:nil];
        {NSLog(@can combine in for loop);}
        else{NSLog(@cannot combine in for loop);}
        startTime = CMTimeAdd(startTime, [asset duration]);


  • Registered Users

    I have checked and I found out my AVURLAsset duration is zero. It is okay for iOS 6 but it is not okay for iOS 7. How shall I do?

            NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
            //testing >> AVURLAsset *asset
            NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
            AVURLAsset *assetToCombine = [AVURLAsset URLAssetWithURL:url options:options];//original
           // AVURLAsset *assetToCombine= [[AVURLAsset alloc] initWithURL:url options:nil];//testing..not okay
            [assetToCombine retain];
            NSArray *requestedKey=[NSArray arrayWithObjects:@duration, nil];
            [assetToCombine loadValuesAsynchronouslyForKeys:requestedKey completionHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    //do nth here
                    NSLog(@dispatch_async assetToCombine.duration.value is %lld.,assetToCombine.duration.value);
            NSLog(@assetToCombine.duration.value is %lld.,assetToCombine.duration.value);
  • Administrators

    dispatch_async assetToCombine.duration.value is 0 ?

    Are you using AVPlayer ? Did you try duration from AVPlayer like below

      self.player = [AVPlayer playerWithPlayerItem:playerItem];
        // changed this from previous value currentItem.asset.duration
        [self.player addObserver:self forKeyPath:@currentItem.duration

    It's using KeyPath to get the duration changes from AVPlayer.

  • edited March 2014 Registered Users

    oh sorry bro. I found out root cause and I don't know how to solve that. I am recording screen with this project. Video file is disrupted after it is saved and that is the reason why I can't open on iPad or computer. It is okay for iOS 6 but not okay for iOS 7. How should I do bro?

Sign In or Register to comment.