视频缩略图不会出现在集合视图中

时间:2015-07-03 06:37:15

标签: ios objective-c uiimage uicollectionview nsarray

self.url = [self grabFileURL:@"video.mov"];
NSLog(@"The URL is: %@", self.url);

AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:self.url options:nil];
AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc] initWithAsset:asset1];
generate1.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 2);
CGImageRef oneRef = [generate1 copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *one = [[UIImage alloc] initWithCGImage:oneRef];

CaptureViewController *cv = [[CaptureViewController alloc]init];
[cv.thumbnail setImage:one];

NSLog(@"The thumbnail is: %@", one);

one = [UIImage imageNamed:@"vid.png"];

videoGallery = [NSArray arrayWithObjects:@"vid.png", nil];

编辑:

- (NSURL*)grabFileURL:(NSString *)fileName {

// find Documents directory
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

// append a file name to it
documentsURL = [documentsURL URLByAppendingPathComponent:fileName];

return documentsURL;
}

NSLog中没有输出错误,但缩略图仍未显示在集合视图控制器中。我错过了什么?

1 个答案:

答案 0 :(得分:1)

-(void)generateImageForImageView:(UIImageView *) imageView withURL:(NSString *) VideoURL
{

    NSURL *url = [NSURL URLWithString:VideoURL];

    AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:url options:nil];
    AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc]     initWithAsset:asset1];
    generate1.appliesPreferredTrackTransform = YES;
    NSError *err = NULL;
    CMTime time = [asset1 duration];
    time.value = 0;
    CGImageRef oneRef = [generate1 copyCGImageAtTime:time actualTime:NULL error:&err];
    UIImage *one = [[UIImage alloc] initWithCGImage:oneRef];
    [imageView setImage:one];
    imageView.contentMode = UIViewContentModeScaleToFill;
}

使用这种方法希望它对你有用,它对我有用