
- (UIImage*) thumbnailImageForVIDeo:(NSURL *)sourceURL{ AVAsset *asset = [AVAsset assetWithURL:sourceURL]; AVAssetimageGenerator *imageGenerator = [[AVAssetimageGenerator alloc]initWithAsset:asset]; NSError *err = NulL; CMTime time = CMTimeMake(1,1); CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NulL error:&err]; NSLog(@"err==%@,imageRef==%@",err,imageRef); UIImage *thumbnail = [[UIImage alloc] initWithCGImage:imageRef]; CGImageRelease(imageRef); // CGImageRef won't be released by ARC return thumbnail;} 这是我使用它的地方:
- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{ libraryCell *libraryCell = [tableVIEw dequeueReusableCellWithIDentifIEr:@"libraryCell" forIndexPath:indexPath]; Nsstring *vIDeoPath = [Nsstring stringWithFormat:@"%@/%@",[NSHomeDirectory() stringByAppendingPathComponent:@"documents"],[libraryfiles objectAtIndex:indexPath.item]]; libraryCell.itemImage.image = [self thumbnailImageForVIDeo:[NSURL URLWithString:vIDeoPath]]; return libraryCell;} 该应用程序不会崩溃,但没有图像.这是我在控制台中看到的:
2013-04-13 23:44:46.828 GeekOut[14433:907] err==Error Domain=NSURLErrorDomain Code=-1 "unkNown error" UserInfo=0x1f0b4610 {NSUnderlyingError=0x1f0b3220 "The operation Couldn’t be completed. (Osstatus error -12935.)",NSLocalizedDescription=unkNown error},imageRef==(null)2013-04-13 23:44:46.859 GeekOut[14433:907] err==Error Domain=NSURLErrorDomain Code=-1 "unkNown error" UserInfo=0x1dd8c660 {NSUnderlyingError=0x1dd8c5c0 "The operation Couldn’t be completed. (Osstatus error -12935.)",imageRef==(null)2013-04-13 23:44:46.893 GeekOut[14433:907] err==Error Domain=NSURLErrorDomain Code=-1 "unkNown error" UserInfo=0x1f0bec80 {NSUnderlyingError=0x1f0be9b0 "The operation Couldn’t be completed. (Osstatus error -12935.)",imageRef==(null)解决方法 您的缩略图提取代码工作正常.问题是你在tableVIEw中初始化NSURL的方式:cellForRowAtIndexPath:. 尝试改变这个:
[NSURL URLWithString:vIDeoPath]
对此:
[NSURL fileURLWithPath:vIDeoPath]总结
以上是内存溢出为你收集整理的ios – 尝试获取视频缩略图全部内容,希望文章能够帮你解决ios – 尝试获取视频缩略图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)