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

Commit 654a025

Browse files
[camera_platform_interface] Added stopRecordingVideo (#3518)
* Added stopRecordingVideo * Removed deprecation and made stopRecordingVideo return void * Removed unused import * Revert pubspec change * Updated documentation * removed stopRecordingVideo * Update packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl> * fixed formatting * Remove coverage folders * Updated documentation * updated version Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl>
1 parent 5aa082f commit 654a025

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
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.6.0
2+
3+
- Added VideoRecordedEvent to support ending a video recording in the native implementation.
4+
15
## 1.5.0
26

37
- Introduces interface methods for locking and unlocking the capture orientation.

packages/camera/camera_platform_interface/lib/src/events/camera_event.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,49 @@ class CameraErrorEvent extends CameraEvent {
235235
@override
236236
int get hashCode => super.hashCode ^ description.hashCode;
237237
}
238+
239+
/// An event fired when a video has finished recording.
240+
class VideoRecordedEvent extends CameraEvent {
241+
/// XFile of the recorded video.
242+
final XFile file;
243+
244+
/// Maximum duration of the recorded video.
245+
final Duration maxVideoDuration;
246+
247+
/// Build a VideoRecordedEvent triggered from the camera with the `cameraId`.
248+
///
249+
/// The `file` represents the file of the video.
250+
/// The `maxVideoDuration` shows if a maxVideoDuration shows if a maximum
251+
/// video duration was set.
252+
VideoRecordedEvent(int cameraId, this.file, this.maxVideoDuration)
253+
: super(cameraId);
254+
255+
/// Converts the supplied [Map] to an instance of the [VideoRecordedEvent]
256+
/// class.
257+
VideoRecordedEvent.fromJson(Map<String, dynamic> json)
258+
: file = XFile(json['path']),
259+
maxVideoDuration = json['maxVideoDuration'] != null
260+
? Duration(milliseconds: json['maxVideoDuration'] as int)
261+
: null,
262+
super(json['cameraId']);
263+
264+
/// Converts the [VideoRecordedEvent] instance into a [Map] instance that can be
265+
/// serialized to JSON.
266+
Map<String, dynamic> toJson() => {
267+
'cameraId': cameraId,
268+
'path': file.path,
269+
'maxVideoDuration': maxVideoDuration?.inMilliseconds
270+
};
271+
272+
@override
273+
bool operator ==(Object other) =>
274+
identical(this, other) ||
275+
super == other &&
276+
other is VideoRecordedEvent &&
277+
runtimeType == other.runtimeType &&
278+
maxVideoDuration == other.maxVideoDuration;
279+
280+
@override
281+
int get hashCode =>
282+
super.hashCode ^ file.hashCode ^ maxVideoDuration.hashCode;
283+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ class MethodChannelCamera extends CameraPlatform {
156156
return _cameraEvents(cameraId).whereType<CameraErrorEvent>();
157157
}
158158

159+
@override
160+
Stream<VideoRecordedEvent> onVideoRecordedEvent(int cameraId) {
161+
return _cameraEvents(cameraId).whereType<VideoRecordedEvent>();
162+
}
163+
159164
@override
160165
Stream<DeviceOrientationChangedEvent> onDeviceOrientationChanged() {
161166
return deviceEventStreamController.stream
@@ -433,6 +438,15 @@ class MethodChannelCamera extends CameraPlatform {
433438
cameraId,
434439
));
435440
break;
441+
case 'video_recorded':
442+
cameraEventStreamController.add(VideoRecordedEvent(
443+
cameraId,
444+
XFile(call.arguments['path']),
445+
call.arguments['maxVideoDuration'] != null
446+
? Duration(milliseconds: call.arguments['maxVideoDuration'])
447+
: null,
448+
));
449+
break;
436450
case 'error':
437451
cameraEventStreamController.add(CameraErrorEvent(
438452
cameraId,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ abstract class CameraPlatform extends PlatformInterface {
8787
throw UnimplementedError('onCameraError() is not implemented.');
8888
}
8989

90+
/// The camera finished recording a video
91+
Stream<VideoRecordedEvent> onVideoRecordedEvent(int cameraId) {
92+
throw UnimplementedError('onCameraTimeLimitReached() is not implemented.');
93+
}
94+
9095
/// The device orientation changed.
9196
///
9297
/// Implementations for this:
@@ -123,7 +128,8 @@ abstract class CameraPlatform extends PlatformInterface {
123128
/// The length of the recording can be limited by specifying the [maxVideoDuration].
124129
/// By default no maximum duration is specified,
125130
/// meaning the recording will continue until manually stopped.
126-
/// The video is returned as a [XFile] after calling [stopVideoRecording].
131+
/// With [maxVideoDuration] set the video is returned in a [VideoRecordedEvent]
132+
/// through the [onVideoRecordedEvent] stream when the set duration is reached.
127133
Future<void> startVideoRecording(int cameraId, {Duration maxVideoDuration}) {
128134
throw UnimplementedError('startVideoRecording() is not implemented.');
129135
}

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.5.0
6+
version: 1.6.0
77

88
dependencies:
99
flutter:

0 commit comments

Comments
 (0)