videoMaximumDuration doesn't limit the duration - ios

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;

Related

iOS 14 - Thumbnails do not display in the UIImagePickerController

Thumbnails do not display in the UIImagePickerController when running on iPhone 11 or real device with iOS 14.
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate=self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:picker animated:YES completion:nil];
Result:
Photos and Albums showing as Blank but when I tap on-screen image will be selected.
For me, it was caused by using
UIScrollView.appearance(whenContainedInInstancesOf: [UINavigationController.self]).backgroundColor = .backgroundPrimaryNew
I don't know why is that, but after I've removed this line it began working again and thumbnails are showing.
Try this
Instead of presenting add UIImagePickerController as subView
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate=self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self.view addSubview:self.picker.view];
[self addChildViewController:self.picker];
[self.picker didMoveToParentViewController:self];

Camera view finder comes up black on iPad

I have an iPhone app that presents a UIImagePickerController for users to take a photo. It works fine on iPhone, iPod and an iPad mini, but on one iPad 3 it comes up like this.
Can anyone think of a reason this would happen? There's nothing blocking the lens, and all other camera apps work fine on the device.
I'm presenting the controller like this:
self.picker = [[UIImagePickerController alloc] init];
self.picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
self.picker.delegate = self;
self.picker.toolbarHidden = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.allowsEditing = NO;
self.picker.showsCameraControls = YES;
if ([UIImagePickerController isFlashAvailableForCameraDevice:UIImagePickerControllerCameraDeviceRear])
{
self.picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
}
[self presentModalViewController:picker animated:YES];
I would really appreciate any help
Thanks

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

UIImagepicker display Image capturing instead of Video recording

I am using UIImagepickerController to capture video in my app.
Sometimes it behaves strangely - that image capturing is coming. Mostly it comes when a new user is registered and try to capture a video or a new ipa file is installed and tested. Eventhough it appears randomly.
When I prompt UIImagepickerController it display take photo button (White button) instead of video record button (Red button)
Here is my code -
UIImagePickerController *imagePicker=[[UIImagePickerController alloc]init];
imagePicker.delegate=self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
}
[self presentViewController:imagePicker animated:YES completion:NULL];
Just try replacing your code with this.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
// picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMoviekUTTypeImage];
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie,nil];
//picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];

UIImagePickerController not respecting video maximum duration on iPad

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;

Resources