From c7a749a7567046f188a18c688e86a557af43c4f3 Mon Sep 17 00:00:00 2001 From: "daniel.roek" Date: Wed, 23 Dec 2020 11:49:00 +0100 Subject: [PATCH 1/5] Added maxVideoDuration to startVideoRecording --- .../camera_platform_interface/CHANGELOG.md | 4 ++++ .../method_channel/method_channel_camera.dart | 7 ++++-- .../platform_interface/camera_platform.dart | 3 ++- .../camera_platform_interface/pubspec.yaml | 2 +- .../method_channel_camera_test.dart | 23 +++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/packages/camera/camera_platform_interface/CHANGELOG.md b/packages/camera/camera_platform_interface/CHANGELOG.md index ea9821e841f9..e071db517919 100644 --- a/packages/camera/camera_platform_interface/CHANGELOG.md +++ b/packages/camera/camera_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0 + +- Added maxVideoDuration to startVideoRecording for implementation of a limitation to the duration of a video recording + ## 1.0.4 - Added the torch option to the FlashMode enum, which when implemented indicates the flash light should be turned on continuously. diff --git a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart index 3bf996fedb19..be26c781e3e7 100644 --- a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart +++ b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart @@ -146,10 +146,13 @@ class MethodChannelCamera extends CameraPlatform { _channel.invokeMethod('prepareForVideoRecording'); @override - Future startVideoRecording(int cameraId) async { + Future startVideoRecording(int cameraId, {Duration maxVideoDuration}) async { await _channel.invokeMethod( 'startVideoRecording', - {'cameraId': cameraId}, + { + 'cameraId': cameraId, + 'maxVideoDuration': maxVideoDuration?.inMilliseconds, + }, ); } diff --git a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart index 6f96079dc55c..fd862e452caf 100644 --- a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart +++ b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart @@ -88,8 +88,9 @@ abstract class CameraPlatform extends PlatformInterface { /// Starts a video recording. /// + /// The length of the recording can be limited by defining the [maxVideoDuration] /// The video is returned as a [XFile] after calling [stopVideoRecording]. - Future startVideoRecording(int cameraId) { + Future startVideoRecording(int cameraId, {Duration maxVideoDuration}) { throw UnimplementedError('startVideoRecording() is not implemented.'); } diff --git a/packages/camera/camera_platform_interface/pubspec.yaml b/packages/camera/camera_platform_interface/pubspec.yaml index 8cb643e84ca6..b6933314d41d 100644 --- a/packages/camera/camera_platform_interface/pubspec.yaml +++ b/packages/camera/camera_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the camera plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 1.0.4 +version: 1.1.0 dependencies: flutter: diff --git a/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart b/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart index c461b1fd583c..6e60e402d050 100644 --- a/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart +++ b/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart @@ -411,6 +411,29 @@ void main() { expect(channel.log, [ isMethodCall('startVideoRecording', arguments: { 'cameraId': cameraId, + 'maxVideoDuration': null, + }), + ]); + }); + + test('Should pass maxVideoDuration when starting recording a video', () async { + // Arrange + MethodChannelMock channel = MethodChannelMock( + channelName: 'plugins.flutter.io/camera', + methods: {'startVideoRecording': null}, + ); + + // Act + await camera.startVideoRecording( + cameraId, + maxVideoDuration: Duration(seconds: 10), + ); + + // Assert + expect(channel.log, [ + isMethodCall('startVideoRecording', arguments: { + 'cameraId': cameraId, + 'maxVideoDuration': 10000 }), ]); }); From 131918d820acca7c6a74a626cd2c323b3225c345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl?= <32639467+danielroek@users.noreply.github.com> Date: Wed, 23 Dec 2020 14:43:35 +0100 Subject: [PATCH 2/5] updated documentation Co-authored-by: Maurits van Beusekom --- packages/camera/camera_platform_interface/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera_platform_interface/CHANGELOG.md b/packages/camera/camera_platform_interface/CHANGELOG.md index e071db517919..d117e1c0eba4 100644 --- a/packages/camera/camera_platform_interface/CHANGELOG.md +++ b/packages/camera/camera_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## 1.1.0 -- Added maxVideoDuration to startVideoRecording for implementation of a limitation to the duration of a video recording +- Added an optional `maxVideoDuration` parameter to the `startVideoRecording` method, which allows implementations to limit the duration of a video recording. ## 1.0.4 From 9b3ae14914369868d35082449e1b4dbb77c8ee61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl?= <32639467+danielroek@users.noreply.github.com> Date: Wed, 23 Dec 2020 14:43:43 +0100 Subject: [PATCH 3/5] updated documentation Co-authored-by: Maurits van Beusekom --- .../lib/src/platform_interface/camera_platform.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart index fd862e452caf..73036d577bfd 100644 --- a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart +++ b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart @@ -88,7 +88,7 @@ abstract class CameraPlatform extends PlatformInterface { /// Starts a video recording. /// - /// The length of the recording can be limited by defining the [maxVideoDuration] + /// The length of the recording can be limited by specifying the [maxVideoDuration]. By default no maximum duration is specified, meaning the recording will continue until manually stopped. /// The video is returned as a [XFile] after calling [stopVideoRecording]. Future startVideoRecording(int cameraId, {Duration maxVideoDuration}) { throw UnimplementedError('startVideoRecording() is not implemented.'); From 3ca25df0e4f39f025cc2a0532223a8ab11836b88 Mon Sep 17 00:00:00 2001 From: "daniel.roek" Date: Wed, 23 Dec 2020 15:19:29 +0100 Subject: [PATCH 4/5] Fixed long line in docs --- .../lib/src/platform_interface/camera_platform.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart index 73036d577bfd..6c8e200c75c2 100644 --- a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart +++ b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart @@ -88,7 +88,9 @@ abstract class CameraPlatform extends PlatformInterface { /// Starts a video recording. /// - /// The length of the recording can be limited by specifying the [maxVideoDuration]. By default no maximum duration is specified, meaning the recording will continue until manually stopped. + /// The length of the recording can be limited by specifying the [maxVideoDuration]. + /// By default no maximum duration is specified, + /// meaning the recording will continue until manually stopped. /// The video is returned as a [XFile] after calling [stopVideoRecording]. Future startVideoRecording(int cameraId, {Duration maxVideoDuration}) { throw UnimplementedError('startVideoRecording() is not implemented.'); From 5e626b9e5678f42f41fa02d68ee612bfc216cc9d Mon Sep 17 00:00:00 2001 From: "daniel.roek" Date: Wed, 23 Dec 2020 16:33:25 +0100 Subject: [PATCH 5/5] Formatting --- .../lib/src/method_channel/method_channel_camera.dart | 3 ++- .../method_channel/method_channel_camera_test.dart | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart index be26c781e3e7..bf2b3d3bd70a 100644 --- a/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart +++ b/packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart @@ -146,7 +146,8 @@ class MethodChannelCamera extends CameraPlatform { _channel.invokeMethod('prepareForVideoRecording'); @override - Future startVideoRecording(int cameraId, {Duration maxVideoDuration}) async { + Future startVideoRecording(int cameraId, + {Duration maxVideoDuration}) async { await _channel.invokeMethod( 'startVideoRecording', { diff --git a/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart b/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart index 6e60e402d050..e3573759fea8 100644 --- a/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart +++ b/packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart @@ -411,12 +411,13 @@ void main() { expect(channel.log, [ isMethodCall('startVideoRecording', arguments: { 'cameraId': cameraId, - 'maxVideoDuration': null, + 'maxVideoDuration': null, }), ]); }); - test('Should pass maxVideoDuration when starting recording a video', () async { + test('Should pass maxVideoDuration when starting recording a video', + () async { // Arrange MethodChannelMock channel = MethodChannelMock( channelName: 'plugins.flutter.io/camera', @@ -431,10 +432,8 @@ void main() { // Assert expect(channel.log, [ - isMethodCall('startVideoRecording', arguments: { - 'cameraId': cameraId, - 'maxVideoDuration': 10000 - }), + isMethodCall('startVideoRecording', + arguments: {'cameraId': cameraId, 'maxVideoDuration': 10000}), ]); });