0

I have a UIPickerController to select videos in my App and it is crashing when selecting videos using the picker. When I feed the MPMoviePlayerController with the URL directly it works fine, but when the URL comes from the UIPickerController, it loads the movie correctly but crashes when the thumbnails are being created.

I have dumped the URL to the console, just after the file is selected and this is what I see

file://localhost/private/var/mobile/Applications/FA667F85-B009-46FA-A0B9-A7345A072651/tmp//trim.Ir0gqx.MOV

first question: why is the double bar before the file name? second question: why the file name comes with a trim prefix if I have editing NO on the picker?

this is the picker code:

- (void) selectMovie:(id) sender {

    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypePhotoLibrary]) {

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

        picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
        picker.delegate = self;
        picker.allowsEditing = NO;
        picker.videoQuality = UIImagePickerControllerQualityTypeHigh; // I've added this trying to make it stop compressing the video, but it won't... any clues?


        UIPopoverController *aPopover = 
            [[UIPopoverController alloc] initWithContentViewController:picker];

        aPopover.delegate = self;


        CGRect myRect = [sender frame];

        [aPopover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

    }   
}



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

{
    NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];  

    if ( [ mediaType isEqualToString:@"public.movie" ]){
            movieURL =  [info objectForKey:UIImagePickerControllerMediaURL];
    } 

    NSLog(@"%@", movieURL);

    [self loadMovie:movieURL];

}
makdad
  • 6,402
  • 3
  • 31
  • 56
Duck
  • 34,902
  • 47
  • 248
  • 470
  • Is the `file://` comes from the UIPicker or from you paste it in directly? – vodkhang Dec 26 '10 at 04:32
  • it comes from the picker... but the strange is the / at the end, before the file name... but it appears to be correct. – Duck Dec 26 '10 at 05:47

2 Answers2

1

My thought is that your app does not have permission to generate thumbnails in the location where the movie is stored. Try copying the movie file out of the photo albums and into your documents directory:

NSFileManager *fm = [NSFileManager defaultManager];
[fm moveItemAtURL:fromURL toURL:toURL error:&error];

Assuming you have a toURL pointing to a filename in your docs directory.

makdad
  • 6,402
  • 3
  • 31
  • 56
  • I think you have a good point and when I read it I was convinced it was the right answer, but I have copied the file from the original location to the docs location and it still crashes during the thumbnail creation... this bug is driving me crazy. – Duck Dec 26 '10 at 05:48
  • I am accepting your answer because it indirectly solved the problem. The problem is that it is impossible to use the asynchronous thumbnail generation from the SDk with videos selected by the picker. I am now using the synchronous method and it is working. Thankssssssssssssss! – Duck Dec 26 '10 at 06:08
0

I only know about the first one, because you need to feed to MPMoviePlayerController a url, a url has to start with a scheme, http://, smtp://, kind of that. file:// is also a scheme for file url

vodkhang
  • 18,639
  • 11
  • 76
  • 110