2017-07-03 86 views
3

我正在整合自定義圖像選擇器,我必須顯示持續時間少於10秒的相機膠捲的視頻。下面的代碼從圖庫中提取所有視頻,但是我想根據持續時間應用謂詞進行過濾。獲取持續時間少於10秒的視頻

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() 

請讓我知道,如果任何人有任何想法關於相同的。 謝謝。

回答

4

只需將條件添加到謂詞

options.predicate = NSPredicate(format: "mediaType = %d AND duration < 10", PHAssetMediaType.video.rawValue) 
相關問題