美文网首页
iCloud 云共享视频处理 PHAsset对象中获取视频数据

iCloud 云共享视频处理 PHAsset对象中获取视频数据

作者: longsan0918 | 来源:发表于2018-04-28 14:32 被阅读47次

    iCloud 云共享视频处理

    • (void)getVideoFromPHAsset:(PHAsset *)asset Complete:(void(^)(NSData *data,NSString *fileName))result{
      NSArray * assetResources = [PHAssetResource assetResourcesForAsset: asset];
      PHAssetResource *resource;
      for (PHAssetResource * assetRes in assetResources) {
      if (assetRes.type == PHAssetResourceTypePairedVideo || assetRes.type == PHAssetResourceTypeVideo) {
      resource = assetRes;
      }
      }
      NSString * fileName = @"tempAssetVideo.mov";
      if (resource.originalFilename) {
      fileName = resource.originalFilename;
      }
      if (asset.mediaType == PHAssetMediaTypeVideo || asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive) {
      PHAssetResourceRequestOptions * options = [[PHAssetResourceRequestOptions alloc] init];
      options.networkAccessAllowed = YES;
      options.progressHandler = ^(double progress) {
      NSLog(@"%f",progress);
      };
      NSString *PATH_MOVIE_FILE = [NSTemporaryDirectory() stringByAppendingPathComponent: fileName];
      [[NSFileManager defaultManager] removeItemAtPath: PATH_MOVIE_FILE error: nil];
      [[PHAssetResourceManager defaultManager] writeDataForAssetResource: resource toFile: [NSURL fileURLWithPath: PATH_MOVIE_FILE] options: options completionHandler: ^(NSError * _Nullable error) {
      NSLog(@"%@",error);
      if (error) {
      [HelpUtil showMessage:@"iCloud云共享视频处理失败" dismissAuto:YES inView:MainWindow];
      result(nil, nil);
      } else {
      NSData *data = [NSData dataWithContentsOfURL: [NSURL fileURLWithPath: PATH_MOVIE_FILE]];
      result(data, fileName);
      }
      }];
      } else {
      result(nil, nil);
      }
      }

    相关文章

      网友评论

          本文标题:iCloud 云共享视频处理 PHAsset对象中获取视频数据

          本文链接:https://www.haomeiwen.com/subject/iyeglftx.html