12

I try this :

 UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.delegate = self;
videoPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
videoPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];
videoPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentViewController:videoPicker animated:YES completion:nil];

but it only show videos from photos part not all video in camera roll. I want to pick all video from Camera roll. Please help me by giving some clue or code. Thanks in advance!

joern
  • 27,354
  • 7
  • 90
  • 105
user3566863
  • 243
  • 1
  • 3
  • 7
  • https://github.com/questbeat/QBImagePicker Might be help you – kb920 Jun 17 '15 at 04:32
  • 2
    Set mediaTypes like `videoPicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];` and try to execute your code. – VRAwesome Jun 17 '15 at 04:56

2 Answers2

18

Here is a compilation and cleanup of the answer above plus a few more details.

(0) Ensure you have these two includes.

#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h> // needed for video types

(1) Add two delegates to your .h file: UINavigationControllerDelegate and UIImagePickerControllerDelegate. For us, it looked like this:

@interface ATHViewController () <UITabBarDelegate, UINavigationControllerDelegate,UIImagePickerControllerDelegate>

(2) Present the user with choice of videos from their library. Add this code to your .m file somewhere.

    // Present videos from which to choose
    UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
    videoPicker.delegate = self; // ensure you set the delegate so when a video is chosen the right method can be called

    videoPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
    // This code ensures only videos are shown to the end user
    videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];

    videoPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
    [self presentViewController:videoPicker animated:YES completion:nil];

(3) Handle the responses from the picker. Add this code to your delegate class.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    // This is the NSURL of the video object
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

    NSLog(@"VideoURL = %@", videoURL);
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

(4) Handle when the user cancels choosing anything.

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:NULL];
}
Praxiteles
  • 5,802
  • 9
  • 47
  • 78
6

Please use the following code to select video from iOS gallery

UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.delegate = self;
videoPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
videoPicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];‌​
videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];
videoPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentViewController:videoPicker animated:YES completion:nil];

Please have a look at this link Select video from gallery

Vinodh
  • 5,262
  • 4
  • 38
  • 68
  • 2
    #import to get rid of the error "undeclared identifier type kuTTypeAVIMovie" from this code – Praxiteles Jul 11 '15 at 07:26
  • 1
    Aren't you overwriting values to videoPicker.mediatypes here? (Your first value is getting ignored.) You can delete your first definition of videoPicker.mediaTypes and this code still appears to be working. – Praxiteles Jul 11 '15 at 08:10