Skip to content

Commit edd6a1b

Browse files
danielroekmvanbeusekom
authored andcommitted
[camera] Added maxVideoDuration to startVideoRecording (flutter#3365)
* Added maxVideoDuration to startVideoRecording * updated documentation Co-authored-by: Maurits van Beusekom <[email protected]> * updated documentation Co-authored-by: Maurits van Beusekom <[email protected]> * Fixed long line in docs * Formatting Co-authored-by: Maurits van Beusekom <[email protected]>
1 parent 477781b commit edd6a1b

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

packages/camera/camera_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.0
2+
3+
- Added an optional `maxVideoDuration` parameter to the `startVideoRecording` method, which allows implementations to limit the duration of a video recording.
4+
15
## 1.0.4
26

37
- Added the torch option to the FlashMode enum, which when implemented indicates the flash light should be turned on continuously.

packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ class MethodChannelCamera extends CameraPlatform {
146146
_channel.invokeMethod<void>('prepareForVideoRecording');
147147

148148
@override
149-
Future<void> startVideoRecording(int cameraId) async {
149+
Future<void> startVideoRecording(int cameraId,
150+
{Duration maxVideoDuration}) async {
150151
await _channel.invokeMethod<void>(
151152
'startVideoRecording',
152-
<String, dynamic>{'cameraId': cameraId},
153+
<String, dynamic>{
154+
'cameraId': cameraId,
155+
'maxVideoDuration': maxVideoDuration?.inMilliseconds,
156+
},
153157
);
154158
}
155159

packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ abstract class CameraPlatform extends PlatformInterface {
8888

8989
/// Starts a video recording.
9090
///
91+
/// The length of the recording can be limited by specifying the [maxVideoDuration].
92+
/// By default no maximum duration is specified,
93+
/// meaning the recording will continue until manually stopped.
9194
/// The video is returned as a [XFile] after calling [stopVideoRecording].
92-
Future<void> startVideoRecording(int cameraId) {
95+
Future<void> startVideoRecording(int cameraId, {Duration maxVideoDuration}) {
9396
throw UnimplementedError('startVideoRecording() is not implemented.');
9497
}
9598

packages/camera/camera_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A common platform interface for the camera plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 1.0.4
6+
version: 1.1.0
77

88
dependencies:
99
flutter:

packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,32 @@ void main() {
411411
expect(channel.log, <Matcher>[
412412
isMethodCall('startVideoRecording', arguments: {
413413
'cameraId': cameraId,
414+
'maxVideoDuration': null,
414415
}),
415416
]);
416417
});
417418

419+
test('Should pass maxVideoDuration when starting recording a video',
420+
() async {
421+
// Arrange
422+
MethodChannelMock channel = MethodChannelMock(
423+
channelName: 'plugins.flutter.io/camera',
424+
methods: {'startVideoRecording': null},
425+
);
426+
427+
// Act
428+
await camera.startVideoRecording(
429+
cameraId,
430+
maxVideoDuration: Duration(seconds: 10),
431+
);
432+
433+
// Assert
434+
expect(channel.log, <Matcher>[
435+
isMethodCall('startVideoRecording',
436+
arguments: {'cameraId': cameraId, 'maxVideoDuration': 10000}),
437+
]);
438+
});
439+
418440
test('Should stop a video recording and return the file', () async {
419441
// Arrange
420442
MethodChannelMock channel = MethodChannelMock(

0 commit comments

Comments
 (0)