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

前端 未结 7 2460
[愿得一人]
[愿得一人] 2020-12-09 06:13

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.

7条回答
  •  一个人的身影
    2020-12-09 06:57

    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);
     }];
    

提交回复
热议问题