这篇文章主要介绍iOS中沙盒视频缩略图及保存本地的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
创新互联建站主营榆社网站建设的网络公司,主营网站建设方案,app软件开发公司,榆社h5微信小程序开发搭建,榆社网站营销推广欢迎榆社等地区企业咨询
具体内容如下
获取缩略图
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中沙盒视频缩略图及保存本地的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!