-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[camera] Limit video length with maxVideoDuration on startVideoRecording #3403
Changes from 1 commit
c7a749a
131918d
9b3ae14
3ca25df
5e626b9
02811b7
b8b07e2
aff2938
532cbb0
50edc53
6e31d7c
d3bab02
ae7365c
ae1b47c
4037b5e
36acc32
5a78233
09dad16
771f116
16e43fb
7cb73ef
759f163
0b4270d
12231da
3b8d6ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -381,7 +381,9 @@ class CameraController extends ValueNotifier<CameraValue> { | |
| /// | ||
| /// The video is returned as a [XFile] after calling [stopVideoRecording]. | ||
| /// Throws a [CameraException] if the capture fails. | ||
| Future<XFile> startVideoRecording({Duration maxVideoDuration}) async { | ||
| /// | ||
| /// TODO: Documentation: when maxVideoDuration listen to Stream with CameraTimeLimitReachedEvent | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remaining TODO (PR is in draft state, but marking these just in case 🙂 ) |
||
| Future<void> startVideoRecording({Duration maxVideoDuration}) async { | ||
| if (!value.isInitialized || _isDisposed) { | ||
| throw CameraException( | ||
| 'Uninitialized CameraController', | ||
|
|
@@ -402,24 +404,9 @@ class CameraController extends ValueNotifier<CameraValue> { | |
| } | ||
|
|
||
| try { | ||
| Completer<XFile> completer = Completer(); | ||
| await CameraPlatform.instance | ||
| .startVideoRecording(_cameraId, maxVideoDuration: maxVideoDuration); | ||
| value = value.copyWith(isRecordingVideo: true, isRecordingPaused: false); | ||
|
|
||
| if (maxVideoDuration != null) { | ||
| await CameraPlatform.instance | ||
| .onCameraTimeLimitReached(_cameraId) | ||
| .listen((event) { | ||
| debugPrint('Video recorded to: ${event.path}'); | ||
| completer.complete(XFile(event.path)); | ||
| value = | ||
| value.copyWith(isRecordingVideo: false, isRecordingPaused: false); | ||
| }); | ||
| return completer.future; | ||
| } else { | ||
| return null; | ||
| } | ||
| } on PlatformException catch (e) { | ||
| throw CameraException(e.code, e.message); | ||
| } | ||
|
|
@@ -498,6 +485,32 @@ class CameraController extends ValueNotifier<CameraValue> { | |
| } | ||
| } | ||
|
|
||
| /// TODO: Documentation | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remaining TODO |
||
| void onCameraTimeLimitReachedEvent({onCameraTimeLimitReached}) { | ||
| if (!value.isInitialized || _isDisposed) { | ||
| throw CameraException( | ||
| 'Uninitialized CameraController', | ||
| 'cameraTimeLimitReachedEventStream was called on uninitialized CameraController', | ||
| ); | ||
| } | ||
| if (!value.isRecordingVideo) { | ||
danielroek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| throw CameraException( | ||
| 'No video is recording', | ||
| 'cameraTimeLimitReachedEventStream was called when no video is recording.', | ||
| ); | ||
| } | ||
| debugPrint('ping'); | ||
|
|
||
| CameraPlatform.instance.onCameraTimeLimitReached(_cameraId).listen((event) { | ||
danielroek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| debugPrint('onCameraTimeLimitReached'); | ||
| value = value.copyWith(isRecordingVideo: false); | ||
| onCameraTimeLimitReached(event.path); | ||
| }); | ||
|
|
||
| debugPrint('pong'); | ||
| return; | ||
| } | ||
|
|
||
| /// Returns a widget showing a live camera preview. | ||
| Widget buildPreview() { | ||
| if (!value.isInitialized || _isDisposed) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -237,21 +237,21 @@ class CameraErrorEvent extends CameraEvent { | |||||
| } | ||||||
|
|
||||||
| class CameraTimeLimitReachedEvent extends CameraEvent { | ||||||
| final String path; | ||||||
| final XFile path; | ||||||
|
||||||
| final XFile path; | |
| final XFile file; |
danielroek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,6 +162,11 @@ class MethodChannelCamera extends CameraPlatform { | |
| .whereType<DeviceOrientationChangedEvent>(); | ||
| } | ||
|
|
||
| @override | ||
| Stream<CameraTimeLimitReachedEvent> onCameraTimeLimitReached(int cameraId) { | ||
|
||
| return _cameraEvents(cameraId).whereType<CameraTimeLimitReachedEvent>(); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> lockCaptureOrientation( | ||
| int cameraId, DeviceOrientation orientation) async { | ||
|
|
@@ -182,11 +187,6 @@ class MethodChannelCamera extends CameraPlatform { | |
| ); | ||
| } | ||
|
|
||
| @override | ||
| Stream<CameraTimeLimitReachedEvent> onCameraTimeLimitReached(int cameraId) { | ||
| return _cameraEvents(cameraId).whereType<CameraTimeLimitReachedEvent>(); | ||
| } | ||
|
|
||
| @override | ||
| Future<XFile> takePicture(int cameraId) async { | ||
| String path = await _channel.invokeMethod<String>( | ||
|
|
@@ -210,12 +210,6 @@ class MethodChannelCamera extends CameraPlatform { | |
| 'maxVideoDuration': maxVideoDuration?.inMilliseconds, | ||
| }, | ||
| ); | ||
|
|
||
| if (maxVideoDuration != null) { | ||
| await onCameraTimeLimitReached(cameraId).first.then((value) { | ||
| debugPrint('received event'); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -435,7 +429,7 @@ class MethodChannelCamera extends CameraPlatform { | |
| case 'max_time_limit_reached': | ||
| cameraEventStreamController.add(CameraTimeLimitReachedEvent( | ||
| cameraId, | ||
| call.arguments['path'], | ||
| XFile(call.arguments['path']), | ||
| )); | ||
| break; | ||
| case 'resolution_changed': | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.