iosobjective-cvideouiimagepickercontroller

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: enter image description here


Solution

  • make sure you set allowsEditing to YES before presenting the controller.

    imagePickerController.allowsEditing = YES;