fetch videos with duration less than 10 seconds

Viewed 966

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.

1 Answers
Related