Picking video from PhotoLibrary with UIImagePickerController in OS 3.1

Ben picture Ben · Oct 7, 2009 · Viewed 10.6k times · Source

I am trying to pick a video from the photo library. In principle I know how to do it you set the mediaType of the image picker to an NSArray with kUTTypeMovie as its only object. But this doesn't seem to work on an iPhone 3G. Since OS 3.1 you can store videos you've received in your photo library. When you start the build in 'Photos' application the videos appear. However this doesn't work using the UIImagePickerController. The controller reports that it only supports images. When you try to set the mediaType of the controller with kUTTypeMovie it actually crashes.

If you don't specify the media type only images are shown in the picker.

As anyone managed to pick a video from the photo library? If yes did it only work on the 3gs or on the 3G as well?

Regards

Ben

Answer

lostInTransit picture lostInTransit · Oct 8, 2009

I got the imagepicker working on a 3g and a 3gs to pick videos.

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

And to get the picked video

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
    if([mediaType isEqualToString:@"public.movie"]){...}
}