How do i get only the videos using ALAssetsLibrary

青春壹個敷衍的年華 提交于 2019-12-04 05:09:16

You need to add an ALAssetsFilter to the group during enumeration. Here's a basic example:

ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];

[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    if (group) {
        [group setAssetsFilter:[ALAssetsFilter allVideos]];
        [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
            if (asset){

                NSDictionary *meta = [[asset defaultRepresentation] metadata];

            }
        }];
    }
} failureBlock:^(NSError *error) {
    NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];

For future reference, the available filters are:

- allPhotos
- allVideos
- allAssets
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!