UIImagePickerController not respecting video maximum duration on iPad - ios

I am trying to build an app that would let user pick and upload a video from the library on iPad. I need the max video length to be 30 sec.
I am using the following code:
UIImagePickerController *mediaPicker = [[UIImagePickerController alloc] init];
mediaPicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie,(NSString *)kUTTypeImage,nil];
mediaPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
mediaPicker.videoQuality = UIImagePickerControllerQualityTypeIFrame960x540;
mediaPicker.videoMaximumDuration = 30.0f;
mediaPicker.delegate = self;
if (self.imagePickerPopOverController.popoverVisible) {
[self.imagePickerPopOverController dismissPopoverAnimated:YES];
}
self.imagePickerPopOverController = [[UIPopoverController alloc] initWithContentViewController:mediaPicker];
[self.imagePickerPopOverController presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:NO];
After the video has been picked, I expect the UIImagePickerController to show a trimmer to trim the video length to 30 sec (if its longer), but it does not.

Set this before you present the controller.
imagePickerController.allowsEditing = YES;

Related

Unable to set different video duration for capture and edit video in ios

I am working on project where in i need to set 1 minute for video recording but user should and edit and select the video of 30 second duration.
Below is the code i used to enable 30 second maximum editing time.
-(BOOL)startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate
{
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) || (delegate == nil) || (controller == nil))
{
return NO;
}
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose movie capture
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = YES;
cameraUI.videoMaximumDuration = 30;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: YES];
return YES;
}
Any help would be highly appreciated.
Apple has provided sample for video editing. you can refer that it is AVEditDemo sample is in the WWDC 2010 sample code pack I think so....
videoMaximumDuration can only limit the recording time of the UIImagePickerController.
One solution might be to roll your own camera controls— i.e by setting the showsCameraControls property to NO and providing your own controls in a custom view with the cameraOverlayView property—and have your “capture” button call the image picker controller’s -startVideoCapture and -stopVideoCapture regulated by an NSTimer
for selecting a video and having the trim function enable to a maximum length of 30 sec you can try this code:
-(IBAction)tapSelectVideo:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = #[(NSString *) kUTTypeMovie];
imagePicker.allowsEditing = YES;
[imagePicker setVideoMaximumDuration:30];
[imagePicker setVideoQuality:UIImagePickerControllerQualityTypeMedium];
[self presentViewController:imagePicker animated:YES completion:nil];
}
}

Pick only landscape video / image from photo library

Is there a way to pick only landscape orientation videos from library in objective C ? Does the mediaTypes property has a way to pick only those vides that were recorded in landscape mode? Is there a way to show only landscape recorded videos from library in popOver? Or is there any workaround? This apple doc does not meet my requirement.
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil]; //Any way to pick only landscape videos? Or is there any workaround?
mediaUI.allowsEditing = YES;
mediaUI.delegate = self;
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:mediaUI];
self.popoverController.delegate = self;
[self.popoverController presentPopoverFromRect:CGRectMake(250, self.videoMenuView.frame.origin.y-10, 40, 40) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

Using Tesseract for iOS

Im using tesseract OCR and it only reads 300 dpi images, when i take photos using UIImage picker controller camera the images are in 72 dpi how can i take images in 300 dpi like the stock app in iOS?
I'm using Tesseract on an iPad with iOS7 and the following code successfully presents the UIImagePickerController and I get an image back that I can readily OCR with Tesseract:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
iosPicker = [[UIImagePickerController alloc] init];
iosPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
iosPicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
iosPicker.allowsEditing = NO;
iosPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
iosPicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
iosPicker.modalPresentationStyle = UIModalPresentationFullScreen;
iosPicker.delegate = self;
[self presentViewController:iosPicker animated:YES completion:^{}];
}
Side note: iosPicker is an instance variable defined in the interface for the view controller.

how to load Video from ipad library in ipad app

I have an iPad app in which when I click on the button it opens a popover with the iPad library to see the photos and pics. I want that when I click the button it should also show video in that but it does not show videos.
In device when I see library it shows videos but when popover opens in app it does not show any video.
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if (isiPhone) {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pckrImage animated:YES];
}
}
else {
popOver = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
[popOver presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
First Create normal popover then add this code to for button 'choose photo from gallery'
UIImagePickerController *imagePicker1 = [[UIImagePickerController alloc] init];
imagePicker1.contentSizeForViewInPopover=CGSizeMake(300, 200);
imagePicker1.delegate = self;
imagePicker1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
Popcontroller = [[UIPopoverController alloc] initWithContentViewController:imagePicker1];
[Popcontroller presentPopoverFromRect:cell1.ButtonAddPicture.frame
inView:cell1.ButtonAddPicture.superview
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
and for video add following line to above code
imagePicker1.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];

videoMaximumDuration doesn't limit the duration

I would like the user to pick a video from his libary and limit it to 45 seconds (Like WhatsApp - you can edit the video and the video which will be sent is not longer than 45 seconds.
But if I use the following code, it does pick a video regardless of the duration, and I cant trim it (Tested it with a video, length 1 minute)
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.videoQuality = UIImagePickerControllerQualityTypeLow;
imagePickerController.videoMaximumDuration = 45.0f; //?
imagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[[self parentViewController] presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
In WhatsApp, I get the following screen, which I want to reproduce:
make sure you set allowsEditing to YES before presenting the controller.
imagePickerController.allowsEditing = YES;

Resources