Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[image_picker]Add argument maxDuration to video record #674

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -454,15 +460,15 @@ 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");
}
}

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");
}
}

Expand Down
7 changes: 7 additions & 0 deletions packages/image_picker/ios/Classes/ImagePickerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,16 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
(NSString *)kUTTypeMPEG4
];
_imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary extra blank line.


_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];

Expand Down
11 changes: 11 additions & 0 deletions packages/image_picker/lib/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> pickVideo({
@required ImageSource source,
double maxDuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a doc comment to pickVideo that documents this function (similarly to how it is done for pickImage) and also describe the new parameter maxDuration in there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: would it be better if maxDuration is actually of type Duration? Currently it is unclear what the unit for durations is. Seconds? Minutes? Hours?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a note that the maxDuration is in Seconds.

}) async {
assert(source != null);

double durationSeconds = (maxDuration==null) ? null : maxDuration.inSeconds.toDouble();

final String path = await _channel.invokeMethod(
'pickVideo',
<String, dynamic>{
'source': source.index,
'maxDuration':durationSeconds
},
);
return path == null ? null : new File(path);
Expand Down