从 DKAssets 获取视频

Fetch videos from DKAssets

我正在使用 DKImagePicker 来选择多个图像和视频。我正在获取图片,但不知道如何获取视频?
在下面分享我迄今为止尝试过的代码。
请指导。

func setImage()
{        
    let pickerController = DKImagePickerController()
    pickerController.showsCancelButton = true
    pickerController.showsEmptyAlbums = false

    pickerController.didSelectAssets = { (assets: [DKAsset]) in
        print("didSelectAssets")

        self.assets1 = assets
        print(assets.count)

        for asset in assets {
            asset.fetchImageWithSize(PHImageManagerMaximumSize, completeBlock: { image, info in
                if let img = image {
                    // let fixOrientationImage=img.fixOrientation()

                    User.sharedInstance.arrRoomGalleryImages.addObject(img)
                    print("array after selecting images and videos", User.sharedInstance.arrRoomGalleryImages)

                    kAppDelegate.imageSelected = true
                }
            })
        }

    }
    if(!(kAppDelegate.imageSelected))
    {
        self.presentViewController(pickerController, animated: true)     {}
    }
}

要获取视频,DKAsset 有一个 属性 isVideo。好好利用吧。

for asset in self.assets {
  if asset.isVideo == true {
    asset.fetchAVAsset(.None, completeBlock: { video, info in

    })
  } else {
    asset.fetchImageWithSize(PHImageManagerMaximumSize, completeBlock: { image, info in
            if let img = image {
                // let fixOrientationImage=img.fixOrientation()

                User.sharedInstance.arrRoomGalleryImages.addObject(img)
                print("array after selecting images and videos", User.sharedInstance.arrRoomGalleryImages)

                kAppDelegate.imageSelected = true
            }
        })
  }
}

对于视频

for asset in assets {
            if asset.type == .video {
                asset.fetchAVAsset { AVAsset, info in
                    
                    if let videoUrl = AVAsset as? AVURLAsset {
                        print("url: \(videoUrl.url)")
                        let videoData = try Data(contentsOf: videoUrl.url)
                    }
                }
            }
        }