gpt4 book ai didi

ios - 获取 ALAssetGroup 中的照片和视频的计数

转载 作者:行者123 更新时间:2023-11-29 13:04:58 27 4
gpt4 key购买 nike

我像这样枚举我的 ALAssetGroup:

ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {

if (group.isEditable){
NSLog(@"group is %@", group);
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[groups addObject:group];
}

这会将组过滤为仅包含在其 .numberOfAssets 中的照片。但是,我想要同时照片计数视频计数。如果不第二次枚举整个事情,我将如何做到这一点?

最佳答案

ALAssetsLibrary *al = [[ALAssetsLibrary alloc]init];
[al enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if ([[group valueForProperty:ALAssetsGroupPropertyName]isEqualToString:@"MyAlbumName"]) {
NSLog(@"in album");
int nrAssets=[group numberOfAssets];

__block int countVideo;
__block int countPhoto;

countPhoto=countVideo=0;
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{

if ([[asset valueForProperty:ALAssetPropertyType]isEqualToString:ALAssetTypeVideo]) {
NSLog(@"eVideo ... count++");
countVideo++;
}
else if(asset valueForProperty:ALAssetPropertyType]isEqualToString:AlAssetTypeVideo]){
NSLog(@"EPhoto ... ");
countPhoto++;
}

}];
}


}
failureBlock:^(NSError *error) { NSLog(@"Boom!!!");}
];

我将此代码用于特定专辑,但您可以针对所有专辑进行修改,希望对您有所帮助:)

关于ios - 获取 ALAssetGroup 中的照片和视频的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18872609/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com