我想從視頻中獲取縮略圖,表視圖滾動時從視頻中生成圖像時tableview重用單元格我曾嘗試過到目前爲止,此代碼從視頻獲取視頻縮略圖需要時間和tableview從視頻製作新幀時的滾動視圖
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIActivityIndicatorView *indicatorG = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
dispatch_async(dispatch_get_main_queue(), ^{
[indicatorG removeFromSuperview];
[indicatorG startAnimating];
[indicatorG setCenter:Cell.thumbnail.center];
[Cell.thumbnail addSubview:indicatorG];
});
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
float getDuration = CMTimeGetSeconds(asset.duration);
CMTime thumbTime = CMTimeMakeWithSeconds(0,1);
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
if (result != AVAssetImageGeneratorSucceeded) {
NSLog(@"couldn't generate thumbnail, error:%@", error);
}
else{
UIImageView *imgV;
imgV = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:im]];
dispatch_async(dispatch_get_main_queue(), ^{
[indicatorG stopAnimating];
Cell.thumbnail.image = imgV.image;
});
}
// [button setImage:[UIImage imageWithCGImage:im] forState:UIControlStateNormal];
};
CGSize maxSize = CGSizeMake(320, 180);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];
});
但使用調度異步解決的tableview滾動的問題,新的問題是被幹擾與此代碼的縮略圖的順序,有人請幫助?
編輯:
地址代碼:
NSString *strUrl = [NSString stringWithFormat:@"%@",url];
NSURL *url = [NSURL URLWithString:strUrl];
讓塊保留單元格的indexPath。這樣你的訂單就不會搞砸了。 – Mercurial
@Mercurial我是iOS新手,你能詳細解釋一下嗎? – John
你的網址對於每個表格行是不同的? – 3stud1ant3