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
Show all changes
23 commits
Select commit Hold shift + click to select a range
1634873
Added maxDuration property to pickVideo method
derTuca Sep 9, 2019
b3e452f
Added additional comment on maxDuration purpose
derTuca Sep 16, 2019
953f22a
Changed pick intent to open gallery instead of documents on Android
derTuca Sep 19, 2019
46e5507
Replaced copy-pasted video ref to image
derTuca Sep 19, 2019
09bead9
Revert "Changed pick intent to open gallery instead of documents on A…
derTuca Nov 15, 2019
6e6feee
Revert project.pbxproj
derTuca Nov 15, 2019
9a449b7
Add iskindof check for argument
derTuca Nov 15, 2019
d5d3a90
Merge branch 'master' into image_picker_max_duration
derTuca Nov 16, 2019
254ffd0
Update AUTHORS
Nov 20, 2019
97cd154
Merge branch 'master' of github.com:flutter/plugins into image_picker…
derTuca Nov 26, 2019
2e03c76
Added const initializers for Duation
derTuca Nov 26, 2019
5a88cee
Formatted code using tool
derTuca Nov 26, 2019
bf445eb
Merge branch 'image_picker_max_duration' of github.com:derTuca/plugin…
derTuca Nov 26, 2019
5c9e477
Fixed iOS formatting
derTuca Nov 26, 2019
c901384
Reverted changelog accidental replace and added author to pubspec
derTuca Dec 6, 2019
50a1170
Update CHANGELOG.md
Dec 17, 2019
c83d9ee
Update CHANGELOG.md
Dec 17, 2019
669a420
Merge branch 'master' of github.com:flutter/plugins into image_picker…
derTuca Dec 31, 2019
b6301da
Merge branch 'image_picker_max_duration' of github.com:derTuca/plugin…
derTuca Dec 31, 2019
8a0dd18
Merge branch 'master' of github.com:flutter/plugins into image_picker…
derTuca Feb 2, 2020
1c8c816
Added JUnit test for max duration
derTuca Feb 2, 2020
8822565
Updated changelog and pubspec version
derTuca Feb 18, 2020
e7c7532
Merge branch 'master' of github.com:flutter/plugins into image_picker…
derTuca Feb 18, 2020
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Lukasz Piliszczuk <[email protected]>
SoundReply Solutions GmbH <[email protected]>
Rafal Wachol <[email protected]>
Pau Picas <[email protected]>
Alexandru Tuca <[email protected]>
Rhodes Davis Jr. <[email protected]>
Luigi Agosti <[email protected]>
Quentin Le Guennec <[email protected]>
Expand Down
6 changes: 6 additions & 0 deletions packages/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.4

* Set maximum duration for video recording.

## 0.6.3+2

* Bump RoboElectric dependency to 4.3.1 and update resource usage.
Expand All @@ -12,11 +16,13 @@
* Migrate to using the new e2e test binding.

## 0.6.2+3

* Remove the deprecated `author:` field from pubspec.yaml
* Migrate the plugin to the pubspec platforms manifest.
* Require Flutter SDK 1.10.0 or greater.

## 0.6.2+2

* Android: Revert the image file return logic when the image doesn't have to be scaled. Fix a rotation regression caused by 0.6.2+1
* Example App: Add a dialog to enter `maxWidth`, `maxHeight` or `quality` when picking image.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ public void takeVideoWithCamera(MethodCall methodCall, MethodChannel.Result resu

private void launchTakeVideoWithCameraIntent() {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (this.methodCall != null && this.methodCall.argument("maxDuration") != null) {
int maxSeconds = this.methodCall.argument("maxDuration");
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, maxSeconds);
}
boolean canTakePhotos = intentResolver.resolveActivity(intent);

if (!canTakePhotos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public class ImagePickerDelegateTest {
private static final Double WIDTH = 10.0;
private static final Double HEIGHT = 10.0;
private static final Double MAX_DURATION = 10.0;
private static final Integer IMAGE_QUALITY = 90;

@Mock Activity mockActivity;
Expand Down Expand Up @@ -373,6 +374,19 @@ public void onActivityResult_WhenImageTakenWithCamera_AndNoResizeNeeded_Finishes
verifyNoMoreInteractions(mockResult);
}

@Test
public void
onActivityResult_WhenVideoTakenWithCamera_AndMaxDurationParametersSupplied_FinishesWithFilePath() {
when(mockMethodCall.argument("maxDuration")).thenReturn(MAX_DURATION);

ImagePickerDelegate delegate = createDelegateWithPendingResultAndMethodCall();
delegate.onActivityResult(
ImagePickerDelegate.REQUEST_CODE_TAKE_VIDEO_WITH_CAMERA, Activity.RESULT_OK, mockIntent);

verify(mockResult).success("pathFromUri");
verifyNoMoreInteractions(mockResult);
}

private ImagePickerDelegate createDelegate() {
return new ImagePickerDelegate(
mockActivity,
Expand Down
3 changes: 2 additions & 1 deletion packages/image_picker/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class _MyHomePageState extends State<MyHomePage> {
await _controller.setVolume(0.0);
}
if (isVideo) {
final File file = await ImagePicker.pickVideo(source: source);
final File file = await ImagePicker.pickVideo(
source: source, maxDuration: const Duration(seconds: 10));
await _playVideo(file);
} else {
await _displayPickImageDialog(context,
Expand Down
4 changes: 4 additions & 0 deletions packages/image_picker/ios/Classes/FLTImagePickerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
_arguments = call.arguments;

int imageSource = [[_arguments objectForKey:@"source"] intValue];
if ([[_arguments objectForKey:@"maxDuration"] isKindOfClass:[NSNumber class]]) {
NSTimeInterval max = [[_arguments objectForKey:@"maxDuration"] doubleValue];
_imagePickerController.videoMaximumDuration = max;
}

switch (imageSource) {
case SOURCE_CAMERA:
Expand Down
9 changes: 6 additions & 3 deletions packages/image_picker/lib/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,19 @@ class ImagePicker {
/// The [source] argument controls where the video comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
///
/// The [maxDuration] argument specifies the maximum duration of the captured video. If no [maxDuration] is specified,
/// the maximum duration will be infinite.
///
/// 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,
}) async {
static Future<File> pickVideo(
{@required ImageSource source, Duration maxDuration}) async {
assert(source != null);
final String path = await _channel.invokeMethod<String>(
'pickVideo',
<String, dynamic>{
'source': source.index,
'maxDuration': maxDuration?.inSeconds,
},
);
return path == null ? null : File(path);
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: image_picker
description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker
version: 0.6.3+2
version: 0.6.4

flutter:
plugin:
Expand Down
37 changes: 30 additions & 7 deletions packages/image_picker/test/image_picker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,40 @@ void main() {
expect(
log,
<Matcher>[
isMethodCall('pickVideo', arguments: <String, dynamic>{
'source': 0,
}),
isMethodCall('pickVideo', arguments: <String, dynamic>{
'source': 1,
}),
isMethodCall('pickVideo',
arguments: <String, dynamic>{'source': 0, 'maxDuration': null}),
isMethodCall('pickVideo',
arguments: <String, dynamic>{'source': 1, 'maxDuration': null}),
],
);
});

test('handles a null image path response gracefully', () async {
test('passes the duration argument correctly', () async {
await ImagePicker.pickVideo(source: ImageSource.camera);
await ImagePicker.pickVideo(
source: ImageSource.camera,
maxDuration: const Duration(seconds: 10));
await ImagePicker.pickVideo(
source: ImageSource.camera,
maxDuration: const Duration(minutes: 1));
await ImagePicker.pickVideo(
source: ImageSource.camera, maxDuration: const Duration(hours: 1));
expect(
log,
<Matcher>[
isMethodCall('pickVideo',
arguments: <String, dynamic>{'source': 0, 'maxDuration': null}),
isMethodCall('pickVideo',
arguments: <String, dynamic>{'source': 0, 'maxDuration': 10}),
isMethodCall('pickVideo',
arguments: <String, dynamic>{'source': 0, 'maxDuration': 60}),
isMethodCall('pickVideo',
arguments: <String, dynamic>{'source': 0, 'maxDuration': 3600}),
],
);
});

test('handles a null video path response gracefully', () async {
channel.setMockMethodCallHandler((MethodCall methodCall) => null);

expect(
Expand Down