showing video as well as image in ELCImagepicker
I see a line in your code that says:
elcPicker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie]; //Supports image and movie types
Change that to:
elcPicker.mediaTypes = @[(NSString *)kUTTypeImage]; //Supports image types
and see what happens.
How to pick videos only in ELCImagePickerController?
import in you .m
#import <MobileCoreServices/UTCoreTypes.h>
and in your method
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
elcPicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
Getting video from ALAsset
Here is a clean swift solution to get videos as NSData.
It uses the Photos framework as ALAssetLibrary is deprecated as of iOS9:
IMPORTANT
The Assets Library framework is deprecated as of iOS 9.0. Instead, use the Photos framework instead, which in iOS 8.0 and later provides more features and better performance for working with a user’s photo library. For more information, see Photos Framework Reference.
import Photos
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
self.dismissViewControllerAnimated(true, completion: nil)
if let referenceURL = info[UIImagePickerControllerReferenceURL] as? NSURL {
let fetchResult = PHAsset.fetchAssetsWithALAssetURLs([referenceURL], options: nil)
if let phAsset = fetchResult.firstObject as? PHAsset {
PHImageManager.defaultManager().requestAVAssetForVideo(phAsset, options: PHVideoRequestOptions(), resultHandler: { (asset, audioMix, info) -> Void in
if let asset = asset as? AVURLAsset {
let videoData = NSData(contentsOfURL: asset.URL)
// optionally, write the video to the temp directory
let videoPath = NSTemporaryDirectory() + "tmpMovie.MOV"
let videoURL = NSURL(fileURLWithPath: videoPath)
let writeResult = videoData?.writeToURL(videoURL, atomically: true)
if let writeResult = writeResult where writeResult {
print("success")
}
else {
print("failure")
}
}
})
}
}
}
Related Topics
Indexpathforrowatpoint Returns Nil Only for First Cell in a UItableview
How to Select Table View Row Selection with Custom Checkbox Button
Uicollectionviewcompositionallayout - Center Items in Sections or Groups
Auto Layout How to Hide 1 View in a View with 3 Equal Width Views
Dynamic Cell Height with Sdwebimage
Spritekit Swift Node Count Issues
Why Is Optional("Text") - Swift
How to Send Push Notification to Apns from iOS Device
How to Programmatically Open Apple Watch Companion App from iOS App
How to Convert Cgpoint in Nsvalue in Swift
Googlemap API Gives Wrong Coordinates for Direction Between Two Points
Change Cell Height by The Content of The Textview Inside The Cell
Pass Extra Argument for UItapgesturerecognizer with Selector
How to Solve Mach-O-Linker Error in iOS7 & Xcode 5.0.1
Phonegap Notification.Alert Not Working
Contentview with UItableview Not Scrolling Within UIscrollview