如何使用目标c中的AssetLibrary检索视频的文件大小

时间:2010-10-14 02:38:33

标签: iphone objective-c

我想知道如何使用AssetLibrary检索视频的文件大小?谁能指出我正确的方向?或者可能是一些代码片段?

1 个答案:

答案 0 :(得分:6)

这可以让你走上正轨。见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];
}