NSPredicate to exclude slow motion videos from PHFetchResults

一个人想着一个人 提交于 2019-12-13 06:03:21

问题


NSString *predicateFormat = [NSString stringWithFormat: @"mediaSubtype = %zd", PHAssetMediaSubtypeVideoHighFrameRate];
    NSPredicate *predicate = [NSPredicate predicateWithFormat: predicateFormat];

    PHFetchOptions *fetchOptions = [PHFetchOptions new];
    fetchOptions.predicate = predicate;

    PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumVideos options:fetchOptions];

This is my code to fetch videos which excludes slow motion videos. But I'm getting following error.This doesn't work even if I do like this,

PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"(mediaSubtype & %d) == 0", PHAssetMediaSubtypeVideoHighFrameRate];

Somebody please help. Thanks in advance.

Unsupported predicate in fetch options: mediaSubtype == 131072

回答1:


Try this:

fetchOptions.predicate = [NSPredicate predicateWithFormat:@"(mediaSubtype != %d)", PHAssetMediaSubtypeVideoHighFrameRate];



回答2:


To exclude slow motion videos, the only predicate that worked for me is this:

PHFetchOptions *options = [PHFetchOptions new];
// Disable slow motion videos
options.predicate = [NSPredicate predicateWithFormat:@"NOT ((mediaSubtype & %d) != 0)", PHAssetMediaSubtypeVideoHighFrameRate];



回答3:


Swift 4

let assetFetchOptions = PHFetchOptions()
assetFetchOptions.predicate = NSPredicate(format: "NOT ((mediaSubtype & %d) != 0)", PHAssetMediaSubtype.videoHighFrameRate.rawValue)


来源:https://stackoverflow.com/questions/31939082/nspredicate-to-exclude-slow-motion-videos-from-phfetchresults

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