您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
最近干活要用到操作本地沙盒的文件的一些东西,总结一下 包活图片和视频 获取document文件夹的文件列表 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *plantId = [[DSPKeychainServiceManager sharedManager] getPlantId]; //并给文件起个文件名 NSString *p_w_picpathDir = [[[paths objectAtIndex:0] stringByAppendingPathComponent:@"SMSPictures"] stringByAppendingPathComponent:plantId]; [[NSFileManager defaultManager] createDirectoryAtPath:p_w_picpathDir withIntermediateDirectories:YES attributes:nil error:nil]; // 获取图片列表 NSError *error_img; NSArray *fileList_img = [[NSArray alloc] init]; //fileList_img便是包含有该文件夹下所有文件的文件名及文件夹名的数组 fileList_img = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:p_w_picpathDir error:&error_img]; NSMutableArray *dirArray_img = [[NSMutableArray alloc] init]; BOOL isDir_img = NO; //在上面那段程序中获得的fileList中列出文件夹名 for (NSString *file in fileList_img) { NSString *path = [p_w_picpathDir stringByAppendingPathComponent:file]; [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:(&isDir_img)]; if (!isDir_img) { [dirArray_img addObject:file]; } } 获取视频的缩略图------->(从别家大牛那里转来的) 原文地址:http://blog.sina.com.cn/s/blog_6d01cce301019xym.html 第一种: +(UIImage *)getImage:(NSString *)vi deoURL { AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:videoURL] options:nil]; AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset]; gen.appliesPreferredTrackTransform = YES; CMTime time = CMTimeMakeWithSeconds(0.0, 600); NSError *error = nil; CMTime actualTime; CGImageRef p_w_picpath = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error]; UIImage *thumb = [[UIImage alloc] initWithCGImage:p_w_picpath]; CGImageRelease(p_w_picpath); return thumb; } 第二种: 需要添加AVFoundation和CoreMedia.framework MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:videoURL]; moviePlayer.shouldAutoplay = NO; UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame]; 下面这个也一样 +(UIImage *)fFirstVideoFrame:(NSString *)path { MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; UIImage *img = [mp thumbnailImageAtTime:0.0f timeOption:MPMovieTimeOptionNearestKeyFrame]; return img; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。