From b6e5379880c9af4d225b261c65c85ccaf8349d72 Mon Sep 17 00:00:00 2001 From: Robbie Boyd Date: Thu, 19 Jul 2018 11:19:24 +1200 Subject: [PATCH 1/3] Add argument maxDuration to video record Can pass a double of seconds to maxDuration to limit the duration of the video record --- .../plugins/imagepicker/ImagePickerDelegate.java | 12 ++++++++++-- .../image_picker/ios/Classes/ImagePickerPlugin.m | 9 +++++++++ packages/image_picker/lib/image_picker.dart | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) 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..7022f76a4355 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,14 @@ private void launchTakeVideoWithCameraIntent() { intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri); grantUriPermissions(intent, videoUri); + // Set a maximum duration for the video record + 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 +462,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 +470,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..ed31e95f3ee2 100644 --- a/packages/image_picker/ios/Classes/ImagePickerPlugin.m +++ b/packages/image_picker/ios/Classes/ImagePickerPlugin.m @@ -73,6 +73,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result break; } } else if ([@"pickVideo" isEqualToString:call.method]) { + _imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; _imagePickerController.delegate = self; _imagePickerController.mediaTypes = @[ @@ -80,9 +81,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result (NSString *)kUTTypeMPEG4 ]; _imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh; + _result = result; _arguments = call.arguments; + + // Set a maximum duration for the video record + 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..d4eadf6dbf9c 100755 --- a/packages/image_picker/lib/image_picker.dart +++ b/packages/image_picker/lib/image_picker.dart @@ -58,6 +58,7 @@ class ImagePicker { static Future pickVideo({ @required ImageSource source, + double maxDuration }) async { assert(source != null); @@ -65,6 +66,7 @@ class ImagePicker { 'pickVideo', { 'source': source.index, + 'maxDuration':maxDuration }, ); return path == null ? null : new File(path); From 62cc92ae03e994158aa59b465e61d47d69e07c65 Mon Sep 17 00:00:00 2001 From: Robbie Boyd Date: Tue, 31 Jul 2018 09:14:04 +1200 Subject: [PATCH 2/3] Implement Pull request feedback Remove extra white space and document ImagePicker.pickVideo method channel --- .../flutter/plugins/imagepicker/ImagePickerDelegate.java | 2 -- packages/image_picker/ios/Classes/ImagePickerPlugin.m | 2 -- packages/image_picker/lib/image_picker.dart | 9 ++++++++- 3 files changed, 8 insertions(+), 5 deletions(-) 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 7022f76a4355..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,14 +237,12 @@ private void launchTakeVideoWithCameraIntent() { intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri); grantUriPermissions(intent, videoUri); - // Set a maximum duration for the video record 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 ed31e95f3ee2..765783154788 100644 --- a/packages/image_picker/ios/Classes/ImagePickerPlugin.m +++ b/packages/image_picker/ios/Classes/ImagePickerPlugin.m @@ -73,7 +73,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result break; } } else if ([@"pickVideo" isEqualToString:call.method]) { - _imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; _imagePickerController.delegate = self; _imagePickerController.mediaTypes = @[ @@ -86,7 +85,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result _result = result; _arguments = call.arguments; - // Set a maximum duration for the video record NSNumber *maxDuration = [_arguments objectForKey:@"maxDuration"]; if (maxDuration != (id)[NSNull null]) { double maxDurationToDouble = [maxDuration doubleValue]; diff --git a/packages/image_picker/lib/image_picker.dart b/packages/image_picker/lib/image_picker.dart index d4eadf6dbf9c..4e78004f8f7a 100755 --- a/packages/image_picker/lib/image_picker.dart +++ b/packages/image_picker/lib/image_picker.dart @@ -56,6 +56,13 @@ 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 @@ -66,7 +73,7 @@ class ImagePicker { 'pickVideo', { 'source': source.index, - 'maxDuration':maxDuration + 'maxDuration': maxDuration }, ); return path == null ? null : new File(path); From 3c3fea2ed411d5b39870f3e442d7f5f5529d7c1a Mon Sep 17 00:00:00 2001 From: Robbie Boyd Date: Mon, 1 Oct 2018 12:50:24 +1300 Subject: [PATCH 3/3] Set a record ma duration from a Duration --- packages/image_picker/lib/image_picker.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/image_picker/lib/image_picker.dart b/packages/image_picker/lib/image_picker.dart index 4e78004f8f7a..7dfe42dc3c1f 100755 --- a/packages/image_picker/lib/image_picker.dart +++ b/packages/image_picker/lib/image_picker.dart @@ -69,11 +69,13 @@ class ImagePicker { }) async { assert(source != null); + double durationSeconds = (maxDuration==null) ? null : maxDuration.inSeconds.toDouble(); + final String path = await _channel.invokeMethod( 'pickVideo', { 'source': source.index, - 'maxDuration': maxDuration + 'maxDuration':durationSeconds }, ); return path == null ? null : new File(path);