UIImagePickerController for movie Item
Asked Answered
A

3

10

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 ?

Appolonia answered 4/9, 2009 at 20:57 Comment(2)
it just takes time to copy the file into the tmp directory of your application's sandbox. you are not given the orignal file, just a copy... so that progress bar is the os copying the file.Tokharian
allowsImageEditing property Deprecated in iOS 3.1Annitaanniversary
A
2

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.").

Audette answered 27/10, 2009 at 13:22 Comment(0)
H
2

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.

Halftrack answered 2/7, 2010 at 9:11 Comment(2)
problems were not solved by iOS 4.2. I am still seeing them. Have you discovered any way to make this work?Sladen
Hello Guys is there any solution to this ?Babb
A
1

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 ?

Appolonia answered 14/11, 2009 at 6:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.