开发者

how to show video or movie file into UIImagePickerController?

开发者 https://www.devze.com 2023-01-02 21:38 出处:网络
I am using UI开发者_开发技巧ImagePickerController that gives user to be able select an existing photo or use the camera to take an image at that time. And i can show that image in my application with

I am using UI开发者_开发技巧ImagePickerController that gives user to be able select an existing photo or use the camera to take an image at that time. And i can show that image in my application with UIImageView.

Now i want to use this ability for movies also. But i couldn't find any way to show the selected movie as an image in my app, just like the Photos app. as you know you can see photos and movies in the same list.


-(IBAction) selectImageSelected : (id)sender
{
    actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image" 
                                            delegate:self
                                   cancelButtonTitle:@"Cancel"
                              destructiveButtonTitle:nil
                                   otherButtonTitles:@"Take Picture", @"Select from gallery", nil];
    [actionSheet showInView:self.parentViewController.tabBarController.view];
}

- (void)actionSheet:(UIActionSheet *)_actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex==0)
    {
        if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] )
        {
            [AlertHandler showAlertMessage:[ErrorMessages getCameraNotFoundMsg] withTitle:@"No Camera Detected"];
            return;
        }
        else
        {
            imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentModalViewController:imagePicker animated:YES];
        }
    }
    else if(buttonIndex==1)
    {
        imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
        [self presentModalViewController:imagePicker animated:YES];
    }
    else
    {
        [actionSheet dismissWithClickedButtonIndex:2 animated:YES];
    }
}

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

    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

    if ([mediaType isEqualToString:@"public.image"]){

        // UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];

        UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

        NSLog(@"found an image");

//      [UIImageJPEGRepresentation(image, 1.0f) writeToFile:[self findUniqueSavePath] atomically:YES];

//      SETIMAGE(image);

        CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);

    }

    else if ([mediaType isEqualToString:@"public.movie"]){

        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

        NSLog(@"found a video");

        NSData *webData = [NSData dataWithContentsOfURL:videoURL];

        //NSData *video = [[NSString alloc] initWithContentsOfURL:videoURL];

//      [webData writeToFile:[self findUniqueMoviePath] atomically:YES];

        CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
        CGSize sixzevid=CGSizeMake(imagePicker.view.bounds.size.width,imagePicker.view.bounds.size.height-100);
        UIGraphicsBeginImageContext(sixzevid);
        [imagePicker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        eventButton.imageView.image=viewImage;
        // NSLog(videoURL);

    }

    [picker dismissModalViewControllerAnimated:YES];

}

/*
- (void)imagePickerController:(UIImagePickerController *)picker 
        didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo1
{
    [imagePicker dismissModalViewControllerAnimated:YES];
    imagePicker.view.hidden = YES;
    eventButton.imageView.image = image;
    imageSelected = YES;
}
*/
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [imagePicker dismissModalViewControllerAnimated:YES];   
    imageSelected = NO;
}


The -thumbnailImageAtTime:timeOption: method of MPMoviePlayerController looks like it might help you get an image to display.


To have the picker view with only movie files

replace

imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];

with

picker.mediaTypes = [NSArray arrayWithObject:@"public.movie"];
0

精彩评论

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

关注公众号