开发者

iPhone - picking a video... URL with two bars?

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]开发者_StackOverflow;

        [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];

}


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜