我按照以下方式枚举我的ALAssetGroup:
ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {
if (group.isEditable){
NSLog(@"group is %@", group);
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[groups addObject:group];
}
这会过滤该群组只有.numberOfAssets
中包含的照片。但是,我希望两者照片数量和视频数量。如果不在第二次列举整个事情,我该怎么做?
答案 0 :(得分:1)
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!!!");}
];
我将此代码用于特定相册,但您可以修改所有相册,希望它可以帮助您:)
答案 1 :(得分:0)
下面的代码块统计所有视频和照片:
__block int videoCount = 0;
__block int photoCount = 0;
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc]init];
[assetLibrary
enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group == nil) {
// enumeration complete
return;
}
int total = group.numberOfAssets;
[group setAssetsFilter:[ALAssetsFilter allVideos]];
int groupVideoCount = group.numberOfAssets;
videoCount += groupVideoCount;
photoCount += total - groupVideoCount;
}
failureBlock:^(NSError *error) {
// Handle error
}];