iOS中沙盒视频缩略图及保存本地的示例分析-创新互联
这篇文章主要介绍iOS中沙盒视频缩略图及保存本地的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
具体内容如下
获取缩略图
func thumbnailOfVideo(path : String)-> UIImage { do { let asset = AVURLAsset(url: URL(fileURLWithPath: path), options: nil) let imgGenerator = AVAssetImageGenerator(asset: asset) imgGenerator.appliesPreferredTrackTransform = true let cgImage = try imgGenerator.copyCGImage(at: CMTimeMakeWithSeconds(1, 24), actualTime: nil) let uiImage = UIImage(cgImage: cgImage) return uiImage } catch { return UIImage(named: "default_figure")! } }
保存到系统相册
#import- (void)saveVideoIntoAlbum { NSString *fileDirectory = NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *fileArray = [fileManager contentsOfDirectoryAtPath:fileDirectory error:nil]; NSString *filePath = [fileDirectory stringByAppendingPathComponent:[fileArray lastObject]]; NSURL *fileUrl = [NSURL fileURLWithPath:filePath]; NSLog(@"fileUrl = %@", fileUrl); ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init]; if ([assetslibrary videoAtPathIsCompatibleWithSavedPhotosAlbum:fileUrl]) { [assetslibrary writeVideoAtPathToSavedPhotosAlbum:fileUrl completionBlock:^(NSURL *assetURL, NSError *error) { NSLog(@"%@-----%@", assetURL, error); }]; } else { } }
以上是“iOS中沙盒视频缩略图及保存本地的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联网站建设公司行业资讯频道!
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
标题名称:iOS中沙盒视频缩略图及保存本地的示例分析-创新互联
文章网址:http://tyjierui.cn/article/idiso.html