gpt4 book ai didi

ios - 视频缩略图未出现在 Collection View 中

转载 作者:行者123 更新时间:2023-11-29 01:53:06 24 4
gpt4 key购买 nike

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 中没有输出错误,但缩略图仍然没有显示在 Collection View Controller 中。我错过了什么?

最佳答案

-(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;
}

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

关于ios - 视频缩略图未出现在 Collection View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31200142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com