Skip UIImagePickerController Preview View? - iphone

I'm using UIImagePickerController to allow my user to select a video from the asset library.
When the UIImagePickerController is initially displayed, it shows thumbnails for the various movies that have been recorded.
Once the user selects a movie, it displays a "preview" view which allows them to playback and potentially edit the selected movie.
Is there any way to avoid displaying this view and instead return the movie that was selected on the thumbnail screen?
Here is the code I'm using:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];

I haven't tested this myself, though I'll be attempting this in my own application shortly. If you take a look at the UIImagePickerController showsCameraControls documentation, it alludes to the fact that if you eliminate the camera controls you can take as many photos as you want.
So theoretically if you set showsCameraControls to NO, and assign your own cameraOverlayView UIView to let the user take a photo, you can dismiss the image picker without the preview view from showing.

Perhaps that helps. You could listen with the NSNotificationCenter on #"_UIImagePickerControllerUserDidCaptureItem". If the user select the item, you could dismiss the imagePicker and do your thumbnail stuff.
I had a similar issue, to remove an overlay on the preview view and could solve it with this approach.

Related

Imagepicker for AVCaptureSession

I implemented code for taking picture using AVCaptureSession. And i have button to pick image from Gallery. So, i need to use UIImagePickerController for picking image from gallery.
Is it possible to use UIImagepicker for picking Gallery and AVCaptureSession for taking picture. If i use this inside same app, appstore reject app or not?
Sure. You want to create your UIImagePickerController with a sourceType of UIImagePickerControllerSourceTypePhotoLibrary:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
I can't imagine that Apple would reject you for doing this in the same app that you're using AVCaptureSession - they're providing these classes to do exactly what you're proposing, after all.

MPMoviePlayerController dismisses my UIImagePickerController

I have an iPhone app where I load an UIImagePickerController onto a UIViewController. I then have a custom view on top of the camera. Now when the user takes a photo it is loaded onto a UIImageView which presents it to the user asking if you want to use that photo or take another (removing the image from the UIImageView). This works perfectly.
Now If the user has just recorded a video I wanted to take a snapshot preview somewhere in the video and present it as a static image in the same UIImageView. I do this with the following code:
MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc] init];
videoPlayer.shouldAutoplay = NO;
[videoPlayer setContentURL:[info valueForKey:UIImagePickerControllerMediaURL]];
UIImage *videoScreenShot = [videoPlayer thumbnailImageAtTime:(videoPlayer.duration/2.0) timeOption:MPMovieTimeOptionNearestKeyFrame];
photoPreview.image = videoScreenShot;
[videoPlayer release]
This works as intended. The problem is if I want to take another video. When I call:
[videoPlayer setContentURL:[info valueForKey:UIImagePickerControllerMediaURL]];
The camera shutter closes and the camera is seemingly dismissed. Trying to take a picture or recording video gives me:
UIImagePickerController: ignoring request to take picture; camera is not yet ready.
UIImagePickerController: ignoring request to start video capture; camera is not yet ready.
I've tried calling the following after, which has no effect:
myImagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
[myImagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
I tried adding the UIImagePickerController to the UIIViewController again, which caused some fantastic freeze-ups.
Finally I tried commenting out the UIViewController's [super didReceivedMemoryWarning] line of didReceivedMemoryWarning. Which also had no effect.
I'm guessing MPMoviePlayerController takes over something UIImagePicker also needs. How do I give it back?
I would suggest setting your MPMoviePlayerController to nil before showing the UIImagePickerController, or maybe taking its view out of the interface temporarily. Both of these contain a movie player view, but there can be only one movie player view at a time in your application's interface. Thus they can interfere with each other, and that might be what's happening to you.

Regarding uiimagepickercontroller

In my application i have to upload a image and that image is taken from the ipad camera, now my query is when i choose the button "TakePicture" the cameraview opens can I resize the cameraview which captures the image.
Here is my code.
- (void) takePicture {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
Dont think so, that is an internal ui call,
You might be able to put some custom overlay on the camera view as quite a few other apps do, but to resize the internal camera view is not what apple wants us to do.
But then again, it would be a nice to have as we can use that for some really cool effects!
Do you mean view itself? No, the size couldn't be changed. If you mean size of taken/chosen image, user will be allowed to do resizing if you set allowsEditing to YES.

How to record video in iPhone using Objective-C?

I have a map application in which there is a button named video. If a user clicks on the video button he can record video at any location he like and simultaneously play the video.
How can I do this? My code is as follows:
-(IBAction)video:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType]; if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){ NSLog(#"device not supported"); return; } picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeVideo]; picker.videoQuality = UIImagePickerControllerQualityTypeHigh; [self presentModalViewController:picker animated:YES]; }
From Apple Programming guides
Starting in iPhone OS 3.0, you can
record video, with included audio, on
supported devices. To display the
video recording interface, create and
push a UIImagePickerController object,
just as for displaying the
still-camera interface.
To record video, you must first check that the camera source type
(UIImagePickerControllerSourceTypeCamera)
is available and that the movie media
type (kUTTypeMovie) is available for
the camera. Depending on the media
types you assign to the mediaTypes
property, the picker can directly
display the still camera or the video
camera, or a selection interface that
lets the user choose.
Using the UIImagePickerControllerDelegate
protocol, register as a delegate of
the image picker. Your delegate object
receives a completed video recording
by way of the
imagePickerController:didFinishPickingMediaWithInfo:
method.
On supported devices, you can also pick previously-recorded videos from a
user’s photo library.
For more information on using the image picker class, see
UIImagePickerController Class
Reference. For information on trimming
recorded videos, see
UIVideoEditorController Class
Reference and
UIVideoEditorControllerDelegate
Protocol Reference.
Once you have the video in your UIImagePickerController delegate you can then save it to your app's documents directory using standard file operations.

iOS4: UIImagePickerController behaving weirdly when presented modally

I'm trying to present a UIImagePickerController from a UITableViewController subclass using the following code:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if(library)
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
else
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
[picker release];
If I create a brand new project and throw this code in, it works absolutely fine. However, in this project, for some reason, the UIImagePickerController's view appears as a blank white screen if I try to show the Photo Library, or shows the camera view but with no camera controls if I try to show the Camera.
Is there anything in a UITableViewController subclass that would be causing this? I get complaints about two-stage animations as well, but from what I've been able to find, this is an issue with Apple's code.
For some reason, changing the PRODUCT_NAME in the Info.plist (something which I was going to do anyway but hadn't gotten around to until just now) fixed this issue. I have absolutely no idea why, but I'm going to assume it was some obscure bug in the iPhone SDK.