How to select any Video or Movie file from UIImagePickerController

Picking videos from the iPhone Library does not work on the iOS Simulator. Try it on a real iPhone.

Here is the code for picking video from the iOS Photo Library which I have used in my projects. Just add video method from selector to your desired button.

- (void)video {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,      nil];

    [self presentModalViewController:imagePicker animated:YES];
 }


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

    if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
        NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
        NSString *moviePath = [videoUrl path];

        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
            UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
        }
    }

    [self dismissModalViewControllerAnimated:YES];
    [picker release];
}

The string moviepath gives you the path of the selected video which can be used to perform any desired action with that video.

Don’t forget to add the MobileCoreServices.framework Framework to your project! Then import it like this:

#import <MobileCoreServices/UTCoreTypes.h>

Leave a Comment