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 6ddee11897ed..78b71133319a 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 @@ -259,6 +259,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); } diff --git a/packages/image_picker/ios/Classes/ImagePickerPlugin.m b/packages/image_picker/ios/Classes/ImagePickerPlugin.m index 946cb1be3b56..dc9170403cc5 100644 --- a/packages/image_picker/ios/Classes/ImagePickerPlugin.m +++ b/packages/image_picker/ios/Classes/ImagePickerPlugin.m @@ -84,6 +84,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result _result = result; _arguments = call.arguments; + + NSNumber *maxDuration = [_arguments objectForKey:@"maxDuration"]; + if ([maxDuration isKindOfClass:[NSNumber class]]) { + 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 92c1b3d6b5ea..502012dd9ad2 100755 --- a/packages/image_picker/lib/image_picker.dart +++ b/packages/image_picker/lib/image_picker.dart @@ -70,13 +70,18 @@ class ImagePicker { /// The [source] argument controls where the video comes from. This can /// be either [ImageSource.camera] or [ImageSource.gallery]. /// + /// The [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. + /// /// In Android, the MainActivity can be destroyed for various fo reasons. If that happens, the result will be lost /// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data. static Future pickVideo({ @required ImageSource source, + Duration maxDuration }) async { assert(source != null); - + final double durationSeconds = (maxDuration==null) ? null : maxDuration.inSeconds.toDouble(); + // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter. // https://github.com/flutter/flutter/issues/26431 // ignore: strong_mode_implicit_dynamic_method @@ -84,6 +89,7 @@ class ImagePicker { 'pickVideo', { 'source': source.index, + 'maxDuration':durationSeconds }, ); return path == null ? null : File(path);