0

i have an big problem with my situation

my main problem is i need fetch video one by one do some operation on the video name and save it to the file system and again fetch another video do some operation on the video name and save it to the file system through the loop of asset the problem is completion handler prevent me do that because it saving all videos together without i do any editing and changing the name this save all videos i think it is working on background thread please any help to fix this problem i need handle fetch video one by one

this is my code

    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!)
            })

        }

    }
Mustafa
  • 253
  • 1
  • 7
  • 15

1 Answers1

-1

i think this one is related to your query for Vedios How Can i Get the List of all Video files from Library in ios sdk

for Images 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
}
Community
  • 1
  • 1
MAhipal Singh
  • 4,745
  • 1
  • 42
  • 57
  • yes Eric, but we can take idea from this. and code can be converted to swift. https://objectivec2swift.com/ – MAhipal Singh Sep 29 '16 at 10:01
  • but i don't need fetch all videos my friend i need to access between result handler – Mustafa Sep 29 '16 at 10:02
  • If it can be converted to Swift, do it yourself, please. // The same way we don't answer Java questions with Python answers, a Swift question should have answers in Swift... – Eric Aya Sep 29 '16 at 10:02