Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can i Get the List of all Video files from Library in ios sdk

Tags:

ios

iphone

Hi I'm working On videos , i would like get the list of video files from library to Display and playing the Videos in my app. can any one help me.

like image 310
Nag Raj Avatar asked Jul 11 '13 05:07

Nag Raj


People also ask

How do I see all folders on my iPhone?

Open up the Files app on iOS, choose On My iPhone, and you can see everything that's saved to the phone itself. The folders you see here will typically be divided up by app, and they hold files relating to user settings, downloads, saved files, and so on.


1 Answers

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);
 }];
like image 146
Nag Raj Avatar answered Oct 05 '22 23:10

Nag Raj