tan
tan

Reputation: 233

load the video type in the photo album using AssetsLibrary in objective C

i came across the following piece of code which loads everything from photo album but what should i do if i only wanted to load the video type in the photo album on a table?
thanks in advance.

void (^assetEnumerator)(struct ALAsset *,NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
        if(result != nil){
            NSLog(@"Asset:%@", result);
            [Asset addObject:result];
        }
    };

    void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop){
        if(group != nil){
            [group enumerateAssetsUsingBlock: assetEnumerator];
        }

        [self.tableView reloadData];


    };

    Asset = [[NSMutableArray alloc] init];
    ALAssetsLibrary *Library = [[ALAssetsLibrary alloc] init];
    [Library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                           usingBlock:assetGroupEnumerator 
                         failureBlock:^(NSError *error){
                             NSLog(@"error occurred");
                         }];

Upvotes: 0

Views: 1695

Answers (2)

Sangwon Park
Sangwon Park

Reputation: 464

I think this will be better.

if ([result valueForProperty:ALAssetPropertyType] == ALAssetTypeVideo) {
    // asset is a video
}

Upvotes: 1

Aidan Steele
Aidan Steele

Reputation: 11330

Have a look at the -valueForProperty: instance method of ALAsset. Specifically, in your example with ALAsset *result:

if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
    // asset is a video
}

Upvotes: 1

Related Questions