iosiphoneios4alassetslibrary

Accessing Videos in library using AssetsLibrary framework iPhone?


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 array assets is still empty? What am I doing wrong?

by the way my iPhone is a 3G upgraded to iPhone 4.1.(but assets framework is not giving any error)

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

Solution

  • 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.