Skip to content

Commit

Permalink
[camera_platform_interface] Added stopRecordingVideo (flutter#3518)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and adsonpleal committed Feb 26, 2021
1 parent ce3ad60 commit 596dac7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 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.6.0

- Added VideoRecordedEvent to support ending a video recording in the native implementation.

## 1.5.0

- Introduces interface methods for locking and unlocking the capture orientation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,49 @@ class CameraErrorEvent extends CameraEvent {
@override
int get hashCode => super.hashCode ^ description.hashCode;
}

/// An event fired when a video has finished recording.
class VideoRecordedEvent extends CameraEvent {
/// XFile of the recorded video.
final XFile file;

/// Maximum duration of the recorded video.
final Duration maxVideoDuration;

/// Build a VideoRecordedEvent triggered from the camera with the `cameraId`.
///
/// The `file` represents the file of the video.
/// The `maxVideoDuration` shows if a maxVideoDuration shows if a maximum
/// video duration was set.
VideoRecordedEvent(int cameraId, this.file, this.maxVideoDuration)
: super(cameraId);

/// Converts the supplied [Map] to an instance of the [VideoRecordedEvent]
/// class.
VideoRecordedEvent.fromJson(Map<String, dynamic> json)
: file = XFile(json['path']),
maxVideoDuration = json['maxVideoDuration'] != null
? Duration(milliseconds: json['maxVideoDuration'] as int)
: null,
super(json['cameraId']);

/// Converts the [VideoRecordedEvent] instance into a [Map] instance that can be
/// serialized to JSON.
Map<String, dynamic> toJson() => {
'cameraId': cameraId,
'path': file.path,
'maxVideoDuration': maxVideoDuration?.inMilliseconds
};

@override
bool operator ==(Object other) =>
identical(this, other) ||
super == other &&
other is VideoRecordedEvent &&
runtimeType == other.runtimeType &&
maxVideoDuration == other.maxVideoDuration;

@override
int get hashCode =>
super.hashCode ^ file.hashCode ^ maxVideoDuration.hashCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class MethodChannelCamera extends CameraPlatform {
return _cameraEvents(cameraId).whereType<CameraErrorEvent>();
}

@override
Stream<VideoRecordedEvent> onVideoRecordedEvent(int cameraId) {
return _cameraEvents(cameraId).whereType<VideoRecordedEvent>();
}

@override
Stream<DeviceOrientationChangedEvent> onDeviceOrientationChanged() {
return deviceEventStreamController.stream
Expand Down Expand Up @@ -433,6 +438,15 @@ class MethodChannelCamera extends CameraPlatform {
cameraId,
));
break;
case 'video_recorded':
cameraEventStreamController.add(VideoRecordedEvent(
cameraId,
XFile(call.arguments['path']),
call.arguments['maxVideoDuration'] != null
? Duration(milliseconds: call.arguments['maxVideoDuration'])
: null,
));
break;
case 'error':
cameraEventStreamController.add(CameraErrorEvent(
cameraId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ abstract class CameraPlatform extends PlatformInterface {
throw UnimplementedError('onCameraError() is not implemented.');
}

/// The camera finished recording a video
Stream<VideoRecordedEvent> onVideoRecordedEvent(int cameraId) {
throw UnimplementedError('onCameraTimeLimitReached() is not implemented.');
}

/// The device orientation changed.
///
/// Implementations for this:
Expand Down Expand Up @@ -123,7 +128,8 @@ abstract class CameraPlatform extends PlatformInterface {
/// 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].
/// With [maxVideoDuration] set the video is returned in a [VideoRecordedEvent]
/// through the [onVideoRecordedEvent] stream when the set duration is reached.
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.5.0
version: 1.6.0

dependencies:
flutter:
Expand Down

0 comments on commit 596dac7

Please sign in to comment.