我正在尝试在按钮中显示电影缩略图,供用户在上传之前查看。我正在使用 AVAssetImageGenerator。这里的代码:
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:[NSURL URLWithString:moviePath] options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
CMTime thumbTime = CMTimeMakeWithSeconds(0,30);
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
switch (result) {
case AVAssetImageGeneratorSucceeded:
NSLog(@"Image generator succeeded!");
[imageButton setImage:[UIImage imageWithCGImage:im] forState:UIControlStateNormal];
break;
case AVAssetImageGeneratorCancelled:
NSLog(@"Image generator cancelled!");
NSLog(@"couldn't generate thumbnail, error:%@", error);
[imageButton setTitle:@"Video attached" forState:UIControlStateNormal];
break;
case AVAssetImageGeneratorFailed:
NSLog(@"Image generator failed!");
NSLog(@"couldn't generate thumbnail, error:%@", error);
[imageButton setTitle:@"Video attached" forState:UIControlStateNormal];
break;
default:
break;
}
};
CGSize maxSize = CGSizeMake(320, 180);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];
上面的代码失败并出现此错误:
couldn't generate thumbnail, error:Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo=0x1f90a080 {NSUnderlyingError=0x1f979aa0 "The operation couldn’t be completed. (OSStatus error -12935.)", NSLocalizedDescription=unknown error}
imagePickeController 中的moviePath 变量是:/private/var/mobile/Applications/89FD1D5F-B49C-4E6B-B1AA-7F1CF1F3FE83/tmp//trim.eaEKqI.MOV