Selecting videos less than 10 seconds long
I am integrating a custom image picker and I need to show videos from a camera that is less than 10 seconds long. Below code fetches all videos from gallery, but I want to apply a predicate to filter based on duration.
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 about this. Thank.
+3
source to share