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
danielroek and mvanbeusekom authored Dec 28, 2020
1 parent 7eff062 commit 3ec0d64
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.4

- Added the torch option to the FlashMode enum, which when implemented indicates the flash light should be turned on continuously.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,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
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,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
2 changes: 1 addition & 1 deletion packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,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 3ec0d64

Please sign in to comment.