【发布时间】:2014-03-17 05:57:31
【问题描述】:
我可以在 iOS 6 中成功地将 2 个视频合并为 1 个。但我不知道在 iOS 7 中会发生什么。我遇到了这样的数组错误。
由于未捕获的异常 'NSRangeException' 导致应用程序终止,原因:'* -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
这是我编写的代码的一部分。我已经在代码中显示了哪里错误。我该怎么办?
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];
if(ok)
{NSLog(@"can combine in for loop");}
else{NSLog(@"cannot combine in for loop");}
startTime = CMTimeAdd(startTime, [asset duration]);
}
【问题讨论】:
标签: objective-c ipad ios7 ios6 record