Accessing Videos in library using AssetsLibrary framework iPhone?

后端 未结 4 1258
无人及你
无人及你 2021-01-03 02:58

I am trying to access videos in iPhone library using AssetsLibrary Framework with the help of following code...but when I run the application the code is not working...the a

相关标签:
4条回答
  • 2021-01-03 03:18

    the 4.1 upgrade seems to have 'broken' some of the image picker examples, observe the following lines, which run after the code you have posted:

    NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces;
    [assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];
    

    This gives zero assets both on my 4.1 iPhone and simulator. However changing the groupTypes helps, so set

     NSUInteger groupTypes = ALAssetsGroupAll;
    

    and you should start seeing some assets.

    0 讨论(0)
  • 2021-01-03 03:31

    I am using ELC Image Picker Controller, and it's already using ALAssetsGroupAll and still not showing any videos.

    I solved this by adding an asset filter. You can limit to videos, photos or both. I guess photos-only was the default. Please consider the following line if the above fails:

    [assetGroup setAssetsFilter:[ALAssetsFilter allAssets]];
    
    0 讨论(0)
  • 2021-01-03 03:32

    Double Init:

     NSMutableArray *assets = [[NSMutableArray alloc]init];
     ALAssetsLibrary *library =[[ALAssetsLibrary alloc]init];
    
     void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
     if(result != NULL) {
          NSLog(@"See Asset: %@", result);
          [assets addObject:result];
    
            }
    };
    
    void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
        if(group != nil) {NSLog(@"dont See Asset: ");
                [group enumerateAssetsUsingBlock:assetEnumerator];
        }
    };
    
       assets = [[NSMutableArray alloc] init];
       library = [[ALAssetsLibrary alloc] init**];
       [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                           usingBlock:assetGroupEnumerator
                         failureBlock: ^(NSError *error) {
                                 NSLog(@"Failure");
                             }];
    
    0 讨论(0)
  • 2021-01-03 03:39

    I did this in Xcode 4.1, IOS 5:

    ALAssetsGroupEnumerationResultsBlock assetEnumerator = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if(result != NULL) {
            NSLog(@"See Asset: %@", result);
            [assets addObject:result];
        }
    };
    
    ALAssetsLibraryGroupsEnumerationResultsBlock assetGroupEnumerator = ^(ALAssetsGroup *group, BOOL *stop) {
        if(group != nil) {NSLog(@"dont See Asset: ");
            [group enumerateAssetsUsingBlock:assetEnumerator];
        }
    };
    
    assets = [[NSMutableArray alloc] init];
    library = [[ALAssetsLibrary alloc] init];
    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                           usingBlock:assetGroupEnumerator
                         failureBlock: ^(NSError *error) {
                             NSLog(@"Failure");
                         }];
    

    It worked for me.

    0 讨论(0)
提交回复
热议问题