views:

36

answers:

1

Hi, I would like to know how to retrieve the file size of a video using AssetLibrary? Can anyone point me in the right direction? or possible some code snippet?

+1  A: 

This should get you on the right track. See Assets Library Framework Reference

- (void)logVideoSizes {

    void (^assetEnumerator)(ALAsset *asset, NSUInteger index, BOOL *stop)   {
        if(asset != nil)

        ALAssetsRepresentation* representation = [asset defaultRepresentation];
        NSLog(@"Size = %d", [representation size]);
    }

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

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library enumerateGroupsWithTypes:ALAssetsGroupAll
                           usingBlock:assetGroupEnumerator
                         failureBlock:^(NSError *error) {
                             NSLog(@"A problem occured");
                         }];
    [library release];
}
Rod
Hey, it works! Thanks a lot.
tan