如何使用目标c中的AssetLibrary检索视频的文件大小 [英] how to retrieve the file size of a video using AssetLibrary in objective c

查看:188
本文介绍了如何使用目标c中的AssetLibrary检索视频的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

这会让你走上正轨。请参阅资产图书馆框架参考

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

这篇关于如何使用目标c中的AssetLibrary检索视频的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆