Dhanesh Dhanesh - 2 months ago 23
iOS Question

How to pick videos in imagePicker

here is my code to pick videos from imagePicker:

imagepicker = [[UIImagePickerController alloc] init];
[imagepicker setDelegate:self];

NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagepicker setMediaTypes:mediaTypesAllowed];

imagepicker.wantsFullScreenLayout = YES;

pickImagePop = [[UIPopoverController alloc] initWithContentViewController:imagepicker];

[pickImagePop setDelegate:self];
[pickImagePop presentPopoverFromRect:CGRectMake(60, 100, 1, 20) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[pickImagePop setPopoverContentSize:CGSizeMake(320, 400) animated:YES];


But this code shows photos and videos together in Picker. I want to show only video. How can I do that?

Answer

If you only want videos you should add:

imagepicker.mediaTypes =
[[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];

Remember to add the MobileCoreServices framework to your project.

EDIT:

You should check beforehand which types can be used by the device with the following method.

+ (NSArray *)availableMediaTypesForSourceType:(UIImagePickerControllerSourceType)sourceType

It will return an array with all the media types supported by the device.

Comments