I am integrating custom image picker and i have to show videos from camera roll whose duration is less than 10 seconds. Below code fetches all videos from gallery but i want to apply predicate to filter based on duration as well.
let options = PHFetchOptions()
options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true) ]
options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.video.rawValue)
assets = PHAsset.fetchAssets(with: options)
print(assets ?? "no video found")
collectionView.reloadData()
Please let me know if anyone has any idea regarding the same. Thanks.
Just add the condition to the predicate
options.predicate = NSPredicate(format: "mediaType = %d AND duration < 10", PHAssetMediaType.video.rawValue)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With