Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
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 @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/image_picker/ios/Classes/ImagePickerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
8 changes: 7 additions & 1 deletion packages/image_picker/lib/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,26 @@ 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<File> 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
final String path = await _channel.invokeMethod(
'pickVideo',
<String, dynamic>{
'source': source.index,
'maxDuration':durationSeconds
},
);
return path == null ? null : File(path);
Expand Down