From 48aa0cbe0d392677a2075f80fab3eb1f4583cff2 Mon Sep 17 00:00:00 2001 From: Robbie Boyd Date: Thu, 19 Jul 2018 11:19:24 +1200 Subject: [PATCH 1/2] Add argument maxDuration to video record Can pass a double of seconds to maxDuration to limit the duration of the video record Implement Pull request feedback Remove extra white space and document ImagePicker.pickVideo method channel Set a record ma duration from a Duration --- .../flutter/plugins/imagepicker/ImagePickerDelegate.java | 6 ++++++ packages/image_picker/ios/Classes/ImagePickerPlugin.m | 7 +++++++ packages/image_picker/lib/image_picker.dart | 7 +++++++ 3 files changed, 20 insertions(+) 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..87e4d44577a0 100644 --- a/packages/image_picker/ios/Classes/ImagePickerPlugin.m +++ b/packages/image_picker/ios/Classes/ImagePickerPlugin.m @@ -81,9 +81,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 92c1b3d6b5ea..977d0bba7bf2 100755 --- a/packages/image_picker/lib/image_picker.dart +++ b/packages/image_picker/lib/image_picker.dart @@ -70,20 +70,27 @@ 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, + double maxDuration }) async { assert(source != null); // 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 + double durationSeconds = (maxDuration==null) ? null : maxDuration.inSeconds.toDouble(); + final String path = await _channel.invokeMethod( 'pickVideo', { 'source': source.index, + 'maxDuration':durationSeconds }, ); return path == null ? null : File(path); From a034390704f78803d042d028ea79af9d86cb8499 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Fri, 19 Apr 2019 16:08:47 -0700 Subject: [PATCH 2/2] cosmetic updates --- packages/image_picker/ios/Classes/ImagePickerPlugin.m | 3 +-- packages/image_picker/lib/image_picker.dart | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/image_picker/ios/Classes/ImagePickerPlugin.m b/packages/image_picker/ios/Classes/ImagePickerPlugin.m index 87e4d44577a0..dc9170403cc5 100644 --- a/packages/image_picker/ios/Classes/ImagePickerPlugin.m +++ b/packages/image_picker/ios/Classes/ImagePickerPlugin.m @@ -81,13 +81,12 @@ - (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]) { + if ([maxDuration isKindOfClass:[NSNumber class]]) { double maxDurationToDouble = [maxDuration doubleValue]; [_imagePickerController setVideoMaximumDuration:maxDurationToDouble]; } diff --git a/packages/image_picker/lib/image_picker.dart b/packages/image_picker/lib/image_picker.dart index 977d0bba7bf2..502012dd9ad2 100755 --- a/packages/image_picker/lib/image_picker.dart +++ b/packages/image_picker/lib/image_picker.dart @@ -77,15 +77,14 @@ class ImagePicker { /// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data. static Future pickVideo({ @required ImageSource source, - double maxDuration + 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 - double durationSeconds = (maxDuration==null) ? null : maxDuration.inSeconds.toDouble(); - final String path = await _channel.invokeMethod( 'pickVideo', {