从DKAssets中获取视频

时间:2016-09-20 06:26:38

标签: ios iphone swift uiimagepickercontroller

我正在使用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)     {}
    }
}

1 个答案:

答案 0 :(得分:0)

要获取视频,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
            }
        })
  }
}