Skip to content

Commit

Permalink
[camera] Added maxVideoDuration to startVideoRecording (flutter#3365)
Browse files Browse the repository at this point in the history
* Added maxVideoDuration to startVideoRecording

* updated documentation

Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl>

* updated documentation

Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl>

* Fixed long line in docs

* Formatting

Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl>
  • Loading branch information
2 people authored and Minyewoo committed Jan 12, 2021
1 parent 7fcabe5 commit 980ad38
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/camera/camera_platform_interface/CHANGELOG.md
@@ -1,3 +1,7 @@
## 1.1.0

- Added an optional `maxVideoDuration` parameter to the `startVideoRecording` method, which allows implementations to limit the duration of a video recording.

## 1.0.5

- Added interface to support automatic exposure.
Expand Down
Expand Up @@ -147,10 +147,14 @@ class MethodChannelCamera extends CameraPlatform {
_channel.invokeMethod<void>('prepareForVideoRecording');

@override
Future<void> startVideoRecording(int cameraId) async {
Future<void> startVideoRecording(int cameraId,
{Duration maxVideoDuration}) async {
await _channel.invokeMethod<void>(
'startVideoRecording',
<String, dynamic>{'cameraId': cameraId},
<String, dynamic>{
'cameraId': cameraId,
'maxVideoDuration': maxVideoDuration?.inMilliseconds,
},
);
}

Expand Down
Expand Up @@ -90,8 +90,11 @@ 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 video is returned as a [XFile] after calling [stopVideoRecording].
Future<void> startVideoRecording(int cameraId) {
Future<void> startVideoRecording(int cameraId, {Duration maxVideoDuration}) {
throw UnimplementedError('startVideoRecording() is not implemented.');
}

Expand Down
1 change: 1 addition & 0 deletions packages/camera/camera_platform_interface/pubspec.yaml
Expand Up @@ -3,6 +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.1.0
version: 1.0.5

dependencies:
Expand Down
Expand Up @@ -450,10 +450,32 @@ void main() {
expect(channel.log, <Matcher>[
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, <Matcher>[
isMethodCall('startVideoRecording',
arguments: {'cameraId': cameraId, 'maxVideoDuration': 10000}),
]);
});

test('Should stop a video recording and return the file', () async {
// Arrange
MethodChannelMock channel = MethodChannelMock(
Expand Down

0 comments on commit 980ad38

Please sign in to comment.