views:

190

answers:

2

I am using UIImagePickerController 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.

A: 

-(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; }

rkloves
A: 

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

Thomas Müller
I want in pickerview only movies file..
rkloves