Skip to content

Conversation

blackorbs-dev
Copy link

@blackorbs-dev blackorbs-dev commented Aug 24, 2025

setDescriptionWhileRecording allows switching camera while a video recording is in progress. This feature was only working with camera2 setup, but the camera plugin uses camerax by default. So, this PR includes update to address the issue.

Fixes #148013

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully implements the ability to switch cameras while recording video on Android by introducing a persistent recording mode. The changes are well-structured across the camera, camera_platform_interface, and camera_android_camerax packages. My review includes a few suggestions to improve the code, such as removing some dead code and improving test practices. Please also remember to remove the temporary dependency_overrides from the various pubspec.yaml files before merging.


await controller.startVideoRecording(enablePersistentRecording: true);

sleep(const Duration(seconds: 2));

Choose a reason for hiding this comment

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

medium

Using sleep in tests can lead to flakiness and slow down the test suite. It's better to use asynchronous waiting mechanisms like tester.pump() with a Duration or tester.pumpAndSettle() to wait for specific conditions or UI updates. This makes tests more reliable and often faster.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this also in the camera/camera integration test? I would assume we are using the exact same test.

Copy link
Author

Choose a reason for hiding this comment

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

I've updated both tests to match

@stuartmorgan-g
Copy link
Collaborator

Thanks for the contribution!

All of the changes in camera_android, camera_avfoundation, camera_web, and camera_windows can be reverted, so that this review is scoped to the right set of package reviewers.

  • All existing and new tests are passing.

The native test suites do not currently build; please see the CI failure output and resolve the failures.

stuartmorgan-g added a commit that referenced this pull request Aug 25, 2025
Adds a section to the review agent configuration to try to get it to stop leaving comments like [this one](#9878 (comment)) on federated plugin PRs that are following our standard, documented process.
@stuartmorgan-g stuartmorgan-g added the federated: all_changes PR that contains changes for all packages for a federated plugin change label Aug 25, 2025
@camsim99 camsim99 changed the title [camera] Fix issue 148013: setDescriptionWhileRecording with android camerax [camera_android_camerax] Implement setDescriptionWhileRecording Aug 25, 2025
Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

Thank you so much for your contribution! I'm looking forward to having this feature implemented :)

Took a first pass (at the camera_android_camerax code because the rest can be reverted). Overall looks good, but I think the main changes need a few adjustments.

auto-submit bot pushed a commit that referenced this pull request Aug 26, 2025
…9879)

Adds a section to the review agent configuration to try to get it to stop leaving comments like [this one](#9878 (comment)) on federated plugin PRs that are following our standard, documented process.
@blackorbs-dev
Copy link
Author

I need help on the failing checks @stuartmorgan-g @camsim99. For the repo_checks, I'm having issue with format and federated safety check. I believe the federated check will be fixed when the dependencies overrides are reverted but the format is throwing error:

Formatting .kt files... 
Running command: "java -jar /b/s/w/ir/x/w/packages/script/tool/bin/ktfmt-0.46-jar-with-dependencies.jar camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResultCompat.kt" in /b/s/w/ir/x/w/packages/packages 
Error: Invalid or corrupt jarfile /b/s/w/ir/x/w/packages/script/tool/bin/ktfmt-0.46-jar-with-dependencies.jar 
Failed to format Kotlin files: exit code 1.

Even though there are no issues when I ran it locally:

Formatting .kt files...
Running command: "java -jar /Users/blackorbs/AndroidStudioProjects/packages/script/tool/bin/ktfmt-0.46-jar-with-dependencies.jar camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResultCompat.kt" in /Users/blackorbs/AndroidStudioProjects/packages/packages
Done formatting camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResultCompat.kt
Done formatting camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt

Also, I can't figure out why the tree-status check failed for the last commit.

@camsim99
Copy link
Contributor

@blackorbs-dev Agreed on the federated check, for format, I see the error Error: Invalid or corrupt jarfile /b/s/w/ir/x/w/packages/script/tool/bin/ktfmt-0.46-jar-with-dependencies.jar. Not quite sure what that's about but that's the issue there. My gut is just to re-run it or make sure this branch is up to date with main. I can help debug further if it doesn't go away.

Also, thanks for making edits! I'll take a look soon.

@camsim99
Copy link
Contributor

camsim99 commented Aug 27, 2025

@blackorbs-dev
Copy link
Author

By the way, this PR can also remove this line: https://github.com/flutter/packages/blob/main/packages/camera/camera_android_camerax/README.md#setdescriptionwhilerecording-is-unimplemented-issue-148013 🥳

Noted ✅, I can also revert the dependency overrides right?

@stuartmorgan-g
Copy link
Collaborator

I see the error Error: Invalid or corrupt jarfile /b/s/w/ir/x/w/packages/script/tool/bin/ktfmt-0.46-jar-with-dependencies.jar. Not quite sure what that's about but that's the issue there.

I would guess network or server error downloading the formatter, since it's pulled on demand rather than via cipd.

@stuartmorgan-g
Copy link
Collaborator

I can also revert the dependency overrides right?

See this comment; those are the only ones that should be reverted right now, otherwise all the CI will start failing.

@blackorbs-dev
Copy link
Author

@stuartmorgan-g, @camsim99 I've made edits, only the federated check is failing, please take a look

@blackorbs-dev
Copy link
Author

I think this PR can be re-review @stuartmorgan-g @camsim99

/// * calling [CameraController.setDescription] while a recording is in progress
///
/// Defaults to `false`.
final bool enableAndroidPersistentRecording;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Platform interfaces should not be platform-specific. What if another platform needs this configuration in the future?

The name and documentation should be sufficiently generic that it could apply to any relevant platform, even if not all platforms require it.

Copy link
Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

The example/pubspec.yaml files in the reverted packages should be reverted as well.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@stuartmorgan-g stuartmorgan-g added the triage-android Should be looked at in Android triage label Aug 28, 2025
Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

Thanks for the edits! Left a few more comments, mostly small things.

@@ -275,7 +275,9 @@ void main() {
await controller.initialize();
await controller.prepareForVideoRecording();

await controller.startVideoRecording();
await controller.startVideoRecording(
enableAndroidPersistentRecording: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming enableAndroidPersistentRecording is kept in this PR, this probably needs to be gated by a check for the Android platform.

Copy link
Author

Choose a reason for hiding this comment

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

Done


await controller.startVideoRecording(enablePersistentRecording: true);

sleep(const Duration(seconds: 2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this also in the camera/camera integration test? I would assume we are using the exact same test.

@@ -288,7 +288,7 @@ class AndroidCameraCameraX extends CameraPlatform {
ResolutionSelector? _presetResolutionSelector;

/// The ID of the surface texture that the camera preview is drawn to.
late int _flutterSurfaceTextureId;
int? _flutterSurfaceTextureId;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this change. To me, it implies you no longer have to call createCamera and initializeCamera before doing anything and that should never be the case.

Copy link
Author

Choose a reason for hiding this comment

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

I've reverted the change

// Retrieve info required for correcting the rotation of the camera preview
sensorOrientationDegrees = description.sensorOrientation.toDouble();

if (_flutterSurfaceTextureId != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm wrong but this should never be null; see my comment above.

Copy link
Author

Choose a reason for hiding this comment

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

I've made changes

if (options.enableAndroidPersistentRecording) {
pendingRecording = await pendingRecording?.asPersistentRecording();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding correctly, a developer will have to set enableAndroidPersistentRecording to set description while recording. Let's please make this clear in documentation everywhere: on this method, in the README, and on the setDescriptionWhileRecording method.

Copy link
Author

Choose a reason for hiding this comment

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

Done

/// * lifecycle events
/// * calling [CameraController.setDescription] while a recording is in progress
///
/// Defaults to `false`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I noted this elsewhere but can you clarify in the docs that you need to set this in order to set description while recording on Android?

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -4107,28 +4107,141 @@ void main() {
);

test(
'setDescriptionWhileRecording does not make any calls involving starting video recording',
'setDescriptionWhileRecording changes the camera description',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add to this test or make another to test that if imageCapture and imageAnalysis are bound, then setDescriptionWhileRecording also changes them?

Copy link
Author

Choose a reason for hiding this comment

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

I've included verification for imageCapture and imageAnalysis are bound after setting description

@blackorbs-dev
Copy link
Author

I've made edits based on your comments @stuartmorgan-g @camsim99. Please take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
federated: all_changes PR that contains changes for all packages for a federated plugin change p: camera platform-android triage-android Should be looked at in Android triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[camera_android_camerax] Implement setDescriptionWhileRecording
3 participants