Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c7a749a
Added maxVideoDuration to startVideoRecording
danielroek Dec 23, 2020
131918d
updated documentation
danielroek Dec 23, 2020
9b3ae14
updated documentation
danielroek Dec 23, 2020
3ca25df
Fixed long line in docs
danielroek Dec 23, 2020
5e626b9
Formatting
danielroek Dec 23, 2020
02811b7
Started implementation for Android
danielroek Dec 24, 2020
b8b07e2
WIP: Started implementation of stream when time limit is reached
danielroek Dec 24, 2020
aff2938
Merge remote-tracking branch 'origin/master' into limit_video_length
danielroek Jan 8, 2021
532cbb0
Merge remote-tracking branch 'origin/master' into limit_video_length
danielroek Jan 11, 2021
50edc53
Initial working implementation
danielroek Jan 11, 2021
6e31d7c
Android implementation works
danielroek Jan 11, 2021
d3bab02
Improved implementation
danielroek Jan 11, 2021
ae7365c
Updated README order
danielroek Jan 11, 2021
ae1b47c
removed debugPrints
danielroek Jan 11, 2021
4037b5e
Fixed url in README.md
danielroek Jan 11, 2021
36acc32
Formatting
danielroek Jan 11, 2021
5a78233
Merge remote-tracking branch 'origin/master' into limit_video_length
danielroek Jan 13, 2021
09dad16
Implemented Java feedback
danielroek Jan 13, 2021
771f116
Implemented Event and Stream to notify about videoRecording
danielroek Jan 13, 2021
16e43fb
stopVideoRecording now listens to VideoRecordedEvent
danielroek Jan 13, 2021
7cb73ef
Fixed future returning xFile
danielroek Jan 13, 2021
759f163
finished iOS implementation
Feb 3, 2021
0b4270d
Fixed formatting
Feb 3, 2021
12231da
fixed formatting
Feb 3, 2021
3b8d6ed
Reverted platform_interface changes
danielroek Feb 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Initial working implementation
  • Loading branch information
danielroek committed Jan 11, 2021
commit 50edc53bdabd3728ef018caa7f88965694d10736
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,25 @@ private void initFps(CameraCharacteristics cameraCharacteristics) {
Log.i("Camera", "[FPS Range] is:" + fpsRange);
}

private void prepareMediaRecorder(String outputFilePath, int maxVideoDuration) throws IOException {
private void prepareMediaRecorder(String outputFilePath, Integer maxVideoDuration) throws IOException {
if (mediaRecorder != null) {
mediaRecorder.release();
}

mediaRecorder =
new MediaRecorderBuilder(recordingProfile, outputFilePath)
.setEnableAudio(enableAudio)
.setMediaOrientation(getMediaOrientation())
.setMaxVideoDuration(maxVideoDuration)
.build();
if (maxVideoDuration != null) {
mediaRecorder =
new MediaRecorderBuilder(recordingProfile, outputFilePath)
.setEnableAudio(enableAudio)
.setMediaOrientation(getMediaOrientation())
.setMaxVideoDuration(maxVideoDuration)
.build();
} else {
mediaRecorder =
new MediaRecorderBuilder(recordingProfile, outputFilePath)
.setEnableAudio(enableAudio)
.setMediaOrientation(getMediaOrientation())
.build();
}
}

@SuppressLint("MissingPermission")
Expand Down Expand Up @@ -595,11 +603,13 @@ public void startVideoRecording(Result result, Integer maxVideoDuration) {
recordingVideo = true;
createCaptureSession(
CameraDevice.TEMPLATE_RECORD, () -> mediaRecorder.start(), mediaRecorder.getSurface());
mediaRecorder.setOnInfoListener((mr, what, extra) -> {
if (what == MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
dartMessenger.sendTimeLimitReachedEvent(videoRecordingFile.getPath());
}
});
if(maxVideoDuration != null) {
mediaRecorder.setOnInfoListener((mr, what, extra) -> {
if (what == MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
dartMessenger.sendTimeLimitReachedEvent(videoRecordingFile.getPath());
}
});
}
result.success(null);
} catch (CameraAccessException | IOException e) {
recordingVideo = false;
Expand Down
3 changes: 2 additions & 1 deletion packages/camera/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ class _CameraExampleHomeState extends State<CameraExampleHome>

try {
await controller.startVideoRecording(
maxVideoDuration: const Duration(milliseconds: 5000));
maxVideoDuration: null //const Duration(milliseconds: 5000),
);
} on CameraException catch (e) {
_showCameraException(e);
return;
Expand Down
17 changes: 16 additions & 1 deletion packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class CameraController extends ValueNotifier<CameraValue> {
///
/// The video is returned as a [XFile] after calling [stopVideoRecording].
/// Throws a [CameraException] if the capture fails.
Future<void> startVideoRecording({Duration maxVideoDuration}) async {
Future<XFile> startVideoRecording({Duration maxVideoDuration}) async {
if (!value.isInitialized || _isDisposed) {
throw CameraException(
'Uninitialized CameraController',
Expand All @@ -402,9 +402,24 @@ 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);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera
dependencies:
flutter:
sdk: flutter
camera_platform_interface: ^1.2.0
camera_platform_interface: #^1.5.0
path: ../camera_platform_interface
Comment on lines +11 to +12
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove path

pedantic: ^1.8.0

dev_dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class MethodChannelCamera extends CameraPlatform {

@override
Stream<CameraTimeLimitReachedEvent> onCameraTimeLimitReached(int cameraId) {
return _events(cameraId).whereType<CameraTimeLimitReachedEvent>();
return _cameraEvents(cameraId).whereType<CameraTimeLimitReachedEvent>();
}

@override
Expand Down