亲宝软件园·资讯

展开

iOS沙盒视频缩略图及保存本地 iOS沙盒视频缩略图及保存本地代码

Lawerence 人气:0
想了解iOS沙盒视频缩略图及保存本地代码的相关内容吗,Lawerence在本文为您仔细讲解iOS沙盒视频缩略图及保存本地的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:iOS沙盒视频缩略图,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 <AssetsLibrary/AssetsLibrary.h>
- (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 {
  
 }
}

加载全部内容

相关教程
猜你喜欢
用户评论