Deepak
Deepak

Reputation:

UIImagePickerController for movie Item

I am writing a simple video uploader application on iPhone 3GS where I first direct the user to photos album, and then select the video to share or upload. I am using the UIImagePickerController in the following way:

videoPickerCtrl = [[UIImagePickerController alloc] init];
 videoPickerCtrl.delegate = self;
 videoPickerCtrl.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
 videoPickerCtrl.mediaTypes = [UIImagePickerController  availableMediaTypesForSourceType:videoPickerCtrl.sourceType];   

 videoPickerCtrl.allowsImageEditing = NO;
 videoPickerCtrl.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
 [window addSubview:videoPickerCtrl.view];

But I can see that once the controller is invoked, there is a disturbing video trimming interface that is presented. Once I press "choose", the video is always trimmed no matter whether I touch the trimming controls or not. Is there any way to get around this trimming interface and directly get the path of the video file ?

Upvotes: 10

Views: 14993

Answers (3)

Rocket Garden
Rocket Garden

Reputation: 1196

Interesting problem. This is just for information should anyone else be looking at this. On iPad OS 3.2 I have found some problems retrieving video, although the picker works and I can select video from albums and not just from the camera roll.

Here's my working code frag

The call

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

    picker.delegate = self;
    picker.allowsEditing = NO;
    picker.wantsFullScreenLayout = YES;
    if(!IsEmpty(self.editBackgroundPopover)){
        [self.editBackgroundPopover  setContentViewController:picker animated:YES]; 
    } 

And here is the delegate method

imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self.editBackgroundPopover dismissPopoverAnimated:true];   

NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];  

    //not production code,  do not use hard coded string in real app
    if ( [ mediaType isEqualToString:@"public.image" ]) {                                                                                                        
        NSLog(@"Picked a photo");
    }
    //not production code,  do not use hard coded string in real app
    else if ( [ mediaType isEqualToString:@"public.movie" ]){
        NSLog(@"Picked a movie at URL %@",  [info objectForKey:UIImagePickerControllerMediaURL]);
        NSURL *url =  [info objectForKey:UIImagePickerControllerMediaURL];
        NSLog(@"> %@", [url absoluteString]); 
    } 

    [[picker self] dismissModalViewControllerAnimated:YES];
}

However the video URL which I retrieve from the picker has the form

file:/localhost/private/var/mobile/Applications/C6FAC491-D27D-45A6-B805-951727ED2CEC/tmp/-Tmp-/trim.KOzqps.MOV

So it looks to me that the Video might be being processed through the trimming code even if I'm selecting the video as a whole. Note also that the movie, originally of type m4v when I loaded it through iTunes is of type MOV, which is of course unplayable on the device! I did try playing the URL but I received an alert saying "This kind of movie can't be played"

I don't quite understand what Apple is playing at here, the API appears not to really be usable as a way of loading and playing video from the photo library.

Hopefully IOS 4 will be more forthcoming, but for my iPad app, that's still months away.

Upvotes: 2

Deepak
Deepak

Reputation: 59

Ok so I got it working long back after carefully looking at SDK docs. I am able to get videos from Camera Roll directory on my 3GS. But I can not find any way in which UIImagePickerController can choose video from directories other than Camera Roll(for instance, device's Photo Library where the user syncs videos through iTunes). Is there any standard way in SDK to do that ?

Upvotes: 1

Ole Begemann
Ole Begemann

Reputation: 135588

You should set allowsEditing = NO; instead of allowsImageEditing = NO; (which has been deprecated in 3.1). Then, the trimming interface should not appear unless the selected movie is longer than 10 minutes (from the docs: "Maximum movie duration is 10 minutes. If a user picks a movie that is longer in duration than 10 minutes, they are forced to trim it before saving it.").

Upvotes: 2

Related Questions