您好,登錄后才能下訂單哦!
最近干活要用到操作本地沙盒的文件的一些東西,總結一下 包活圖片和視頻 獲取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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。