diff --git a/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index c4a7d7ecfa53..4d16ada79396 100644 --- a/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -237,6 +237,12 @@ private void launchTakeVideoWithCameraIntent() { intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri); grantUriPermissions(intent, videoUri); + Double maxDuration = methodCall.argument("maxDuration"); + if(maxDuration != null) { + int maxDurationToInt = maxDuration.intValue(); + intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, maxDurationToInt); + } + activity.startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO_WITH_CAMERA); } @@ -454,7 +460,7 @@ private void handleImageResult(String path) { String finalImagePath = imageResizer.resizeImageIfNeeded(path, maxWidth, maxHeight); finishWithSuccess(finalImagePath); } else { - throw new IllegalStateException("Received image from picker that was not requested"); + throw new IllegalStateException("Received images from picker that were not requested"); } } @@ -462,7 +468,7 @@ private void handleVideoResult(String path) { if (pendingResult != null) { finishWithSuccess(path); } else { - throw new IllegalStateException("Received video from picker that was not requested"); + throw new IllegalStateException("Received images from picker that were not requested"); } } diff --git a/packages/image_picker/ios/Classes/ImagePickerPlugin.m b/packages/image_picker/ios/Classes/ImagePickerPlugin.m index 8ddf86c5d5a9..765783154788 100644 --- a/packages/image_picker/ios/Classes/ImagePickerPlugin.m +++ b/packages/image_picker/ios/Classes/ImagePickerPlugin.m @@ -80,9 +80,16 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result (NSString *)kUTTypeMPEG4 ]; _imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh; + _result = result; _arguments = call.arguments; + + NSNumber *maxDuration = [_arguments objectForKey:@"maxDuration"]; + if (maxDuration != (id)[NSNull null]) { + double maxDurationToDouble = [maxDuration doubleValue]; + [_imagePickerController setVideoMaximumDuration:maxDurationToDouble]; + } int imageSource = [[_arguments objectForKey:@"source"] intValue]; diff --git a/packages/image_picker/lib/image_picker.dart b/packages/image_picker/lib/image_picker.dart index 26d09c2c313b..7dfe42dc3c1f 100755 --- a/packages/image_picker/lib/image_picker.dart +++ b/packages/image_picker/lib/image_picker.dart @@ -56,15 +56,26 @@ class ImagePicker { return path == null ? null : new File(path); } + /// Returns a [File] object pointing to the video that was picked. + /// + /// The [source] argument controls where the video comes from. This can + /// be either [ImageSource.camera] or [ImageSource.gallery]. + /// + /// [maxDuration] is the maximum amount of Seconds (eg. 30.0) that is available to be recorded + /// after which the video record will immediately finish and the [File] will be returned static Future pickVideo({ @required ImageSource source, + double maxDuration }) async { assert(source != null); + double durationSeconds = (maxDuration==null) ? null : maxDuration.inSeconds.toDouble(); + final String path = await _channel.invokeMethod( 'pickVideo', { 'source': source.index, + 'maxDuration':durationSeconds }, ); return path == null ? null : new File(path);