PHImageManager.default()。视频的requestAVAsset

时间:2016-09-28 22:41:00

标签: swift3 photosframework

我的情况有很大问题

我的主要问题是我需要逐个获取视频对视频名称进行一些操作并将其保存到文件系统并再次获取另一个视频对视频名称进行一些操作并通过循环将其保存到文件系统中资产问题是完成处理程序阻止我这样做,因为它保存所有视频在一起没有我做任何编辑和更改名称这保存所有视频我认为它是在后台线程工作请任何帮助解决这个问题我需要处理获取视频一个接一个地

这是我的代码

    for asset in arrayOfAssets {
        if asset.mediaType == .video {


               PHImageManager.default().requestAVAsset(forVideo: asset, options: nil, resultHandler: { (AVAsset, AVAudio, info) in
                  // i need access to this place so i can fetch the video one by one and working with the AVAsset 

               })


        }else{
            let imageOp = PHImageRequestOptions()

            PHImageManager.default().requestImage(for: asset, targetSize: CGSize(width:125,height:125), contentMode: .aspectFit, options: imageOp, resultHandler: { (img, info) in
               print(img!)
            })

        }

    }

1 个答案:

答案 0 :(得分:-1)

我认为这个与您的查询有关 对于Vedios How Can i Get the List of all Video files from Library in ios sdk

图片 Get all of the pictures from an iPhone photoLibrary in an array using AssetsLibrary framework?

allVideos = [[NSMutableArray alloc] init];
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];

[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     if (group)
     {
         [group setAssetsFilter:[ALAssetsFilter allVideos]];
         [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
          {
              if (asset)
              {
                  dic = [[NSMutableDictionary alloc] init];
                  ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation];
                  NSString *uti = [defaultRepresentation UTI];
                  NSURL  *videoURL = [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:uti];
                  NSString *title = [NSString stringWithFormat:@"video %d", arc4random()%100];
                  UIImage *image = [self imageFromVideoURL:videoURL];
                  [dic setValue:image forKey:@"image"];
                  [dic setValue:title forKey:@"name"];
                  [dic setValue:videoURL forKey:@"url"];
                  [`allVideos` addObject:dic];
              }
          }];
     else
     {
     }
 }
  failureBlock:^(NSError *error)
 {
     NSLog(@"error enumerating AssetLibrary groups %@\n", error);
 }]; 

--------for ALL PHOTOS
 NSArray *imageArray;
 NSMutableArray *mutableArray;

-(void)getAllPhotosFromCamera
{
    imageArray=[[NSArray alloc] init];
    mutableArray =[[NSMutableArray alloc]init];

    PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
    requestOptions.resizeMode   = PHImageRequestOptionsResizeModeExact;
    requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
    requestOptions.synchronous = true;
    PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];

    NSLog(@"%d",(int)result.count);

    PHImageManager *manager = [PHImageManager defaultManager];
    NSMutableArray *images = [NSMutableArray arrayWithCapacity:[result count]];

    // assets contains PHAsset objects.

    __block UIImage *ima;
    for (PHAsset *asset in result) {
        // Do something with the asset

        [manager requestImageForAsset:asset
                           targetSize:PHImageManagerMaximumSize
                          contentMode:PHImageContentModeDefault
                              options:requestOptions
                        resultHandler:^void(UIImage *image, NSDictionary *info) {
                            ima = image;

                            [images addObject:ima];
                        }];


    }

    imageArray = [images copy];  // You can direct use NSMutuable Array images
}