Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[camera] Added maxVideoDuration to startVideoRecording #3365

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.4

- Added the torch option to the FlashMode enum, which when implemented indicates the flash light should be turned on continuously.
Expand Down
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
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
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
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