import UIKit
class ViewController: UIViewController,ZYQAssetPickerControllerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate{
var imageArray = NSMutableArray()
let moreThan:Int = 8
@IBAction func chooseBtn(sender: UIButton) {
let picker = ZYQAssetPickerController()
picker.maximumNumberOfSelection = self.moreThan+1-self.imageArray.count
picker.assetsFilter = ALAssetsFilter.allPhotos()
picker.showEmptyGroups = false
picker.delegate = self
picker.selectionFilter = NSPredicate(block: { (evaluatedObject, bindings) -> Bool in
let a = evaluatedObject as! ALAsset
a.valueForProperty(ALAssetPropertyType)
if(a.isEqual(ALAssetTypeVideo) == true){
let b = a.valueForProperty(ALAssetPropertyDuration).doubleValue
return b >= 5;
}else{
return true
}
})
self.presentViewController(picker, animated: true, completion: nil)
}
func assetPickerController(picker: ZYQAssetPickerController!, didFinishPickingAssets assets: [AnyObject]!) {
dispatch_async(dispatch_get_global_queue(0, 0)) { () -> Void in
if(self.imageArray.count+assets.count-1>=self.moreThan){
self.imageArray.removeLastObject()
}
for i in 0..<assets.count {
let ass = assets[i] as! ALAsset
let ass1 = ass.defaultRepresentation()
let ass2 = ass1.fullScreenImage().takeUnretainedValue()
let image = UIImage(CGImage:ass2)
let data = UIImageJPEGRepresentation(image, 0.1);
self.imageArray.insertObject(data!, atIndex: 0)
}
dispatch_async(dispatch_get_main_queue(), { () -> Void in
})
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}