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

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对象中获取视频数据)