Skip to content

Commit 980ad38

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 7fcabe5 commit 980ad38

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
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.5
26

37
- Added interface to support automatic exposure.

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
@@ -147,10 +147,14 @@ class MethodChannelCamera extends CameraPlatform {
147147
_channel.invokeMethod<void>('prepareForVideoRecording');
148148

149149
@override
150-
Future<void> startVideoRecording(int cameraId) async {
150+
Future<void> startVideoRecording(int cameraId,
151+
{Duration maxVideoDuration}) async {
151152
await _channel.invokeMethod<void>(
152153
'startVideoRecording',
153-
<String, dynamic>{'cameraId': cameraId},
154+
<String, dynamic>{
155+
'cameraId': cameraId,
156+
'maxVideoDuration': maxVideoDuration?.inMilliseconds,
157+
},
154158
);
155159
}
156160

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
@@ -90,8 +90,11 @@ abstract class CameraPlatform extends PlatformInterface {
9090

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

packages/camera/camera_platform_interface/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +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.1.0
67
version: 1.0.5
78

89
dependencies:

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
@@ -450,10 +450,32 @@ void main() {
450450
expect(channel.log, <Matcher>[
451451
isMethodCall('startVideoRecording', arguments: {
452452
'cameraId': cameraId,
453+
'maxVideoDuration': null,
453454
}),
454455
]);
455456
});
456457

458+
test('Should pass maxVideoDuration when starting recording a video',
459+
() async {
460+
// Arrange
461+
MethodChannelMock channel = MethodChannelMock(
462+
channelName: 'plugins.flutter.io/camera',
463+
methods: {'startVideoRecording': null},
464+
);
465+
466+
// Act
467+
await camera.startVideoRecording(
468+
cameraId,
469+
maxVideoDuration: Duration(seconds: 10),
470+
);
471+
472+
// Assert
473+
expect(channel.log, <Matcher>[
474+
isMethodCall('startVideoRecording',
475+
arguments: {'cameraId': cameraId, 'maxVideoDuration': 10000}),
476+
]);
477+
});
478+
457479
test('Should stop a video recording and return the file', () async {
458480
// Arrange
459481
MethodChannelMock channel = MethodChannelMock(

0 commit comments

Comments
 (0)