views:

1789

answers:

8

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 ?

+2  A: 

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

Ole Begemann
+2  A: 

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 ?

Deepak
A: 

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.

Architek Mobile
A: 

Hai,

I want to UPLOAD video files(From the photoAlbum inside simulator) to server from iPhone app. I am using SDK4.0.

I had implemented the code to show and select video file from UIImagePickerController. I am getting the video files in the photoAlbumn screen. When i click on the video the video player is displayed and a "Choose" button is enabled. If i click on the play button in the player the video is running. But if i click on "Choose" button "Compressing Video" gets displayed and it never enter into next state and the simulator gets hangs.

I searched through google and come across certain solution such as setting videoQuality to high and allowEditing to "NO" but with no clue.

Can anybody come across this issue and rectified this? Please if so give hands to me.

If need code i will post it here.

Thanks Jai

Jaibabu
A: 

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.

deoryp
A: 

Hai deoryp,

Thanks for your reply. But the copying process never stops. 

How to avoid this in the simulator and test the video uploading. can you please give me some work around or any samples that implement it.

thanks Jai

Jaibabu
A: 

Ive the same problem, let me know if you find a solution... Desperately seeking this...

HFD
A: 

Hello HFD. Glad to see your post. I am looking for the workaround. I tried many ways to implement but with waste of effort. I am looking for some source of light on that to avoid compressing and upload it to server. If we come across any solution please feel free to share.

Thanks Jai

Jaibabu