Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[camera] MediaSettings parameter for createCameraWithSettings #3586

Merged
merged 159 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
f294625
added MediaSettings
PROGrand Mar 29, 2023
5ca79b9
updated changelog
PROGrand Mar 29, 2023
e08e046
MediaSettings introduced.
PROGrand Mar 29, 2023
21617de
Merge branch 'flutter:main' into main
PROGrand Mar 29, 2023
59d66d3
excerpts added. formatted.
PROGrand Mar 29, 2023
aeec92e
versions and changelogs
PROGrand Mar 29, 2023
869b787
CameraPlatform.createCameraWithSettings
PROGrand Mar 29, 2023
3cf6030
Merge branch 'main' into main
PROGrand Mar 30, 2023
6ac763e
Merge branch 'flutter:main' into main
PROGrand Mar 30, 2023
a40177a
Update CHANGELOG.md
PROGrand Mar 30, 2023
fea1fc7
Update camera_test.dart
PROGrand Mar 30, 2023
9f71f8d
Update main.dart
PROGrand Mar 30, 2023
4a0ac77
MediaSettings.low removed
PROGrand Mar 30, 2023
8fcf1ae
media settings low
PROGrand Mar 30, 2023
da4ecd8
merger mediasettings
PROGrand Mar 30, 2023
16645ef
resolved multiple @hellohuanlin зкщзÑproposals
PROGrand Mar 30, 2023
d7dea54
fps control
PROGrand Mar 31, 2023
6caea7e
Fixed pausing preview on already paused or closed session.
PROGrand Mar 31, 2023
4bec8f3
Prevent pausing preview on uninitialized controller.
PROGrand Mar 31, 2023
11b43c1
Prevent pausing preview on disposed controller.
PROGrand Mar 31, 2023
772e011
Merge branch 'flutter:main' into main
PROGrand Mar 31, 2023
dbb752d
formatted
PROGrand Mar 31, 2023
7f01b93
Merge branch 'main' into main
PROGrand Apr 5, 2023
3506af1
Update packages/camera/camera_android/CHANGELOG.md
PROGrand Apr 26, 2023
8f95dc2
Update packages/camera/camera/CHANGELOG.md
PROGrand Apr 26, 2023
6b1f96c
bump gradle:7.20 in CHANGELOG
PROGrand Apr 26, 2023
6f97b51
commented feature properties
PROGrand Apr 26, 2023
d96f9d5
android_camera_camerax CHANGELOD update
PROGrand Apr 26, 2023
401adce
revert default enableAudio to false
PROGrand Apr 26, 2023
8edd212
properly commented IntFeature
PROGrand Apr 26, 2023
0a8fe17
clarify test constants
PROGrand Apr 26, 2023
d072dfb
pass logic to to _getTargetResolutionForPreview
PROGrand Apr 26, 2023
accef7c
versions fix
PROGrand Apr 26, 2023
480761c
Update packages/camera/camera_platform_interface/lib/src/types/media_…
PROGrand Apr 26, 2023
bdd74a8
Comments improved
PROGrand Apr 26, 2023
ec5856f
minor version increased.
PROGrand Apr 26, 2023
6736802
resolve upstream conflict
PROGrand Apr 26, 2023
9fdd1e0
Merge branch 'main' into main
PROGrand Apr 26, 2023
8a55d87
merged
PROGrand Jun 5, 2023
7d88b16
merge with camera: 0.10.5+2
PROGrand Jun 5, 2023
86c95e9
flutter 3.10.3 + analysis: error 'Found an extra analysis_options.yaml'
PROGrand Jun 5, 2023
c78cfc5
multiple analysis issues: const, await etc.
PROGrand Jun 5, 2023
5597838
expectLater for exceptions checking on async methods
PROGrand Jun 5, 2023
d006820
order of call and verify for mockito is important
PROGrand Jun 5, 2023
f60804d
ios tests passed
PROGrand Jun 5, 2023
d21dd5b
lint suppress
PROGrand Jun 5, 2023
b08f5f1
annotation imports
PROGrand Jun 5, 2023
d361800
mark IntFeature usages as NonNull
PROGrand Jun 5, 2023
a29b222
IntFeature NonNull
PROGrand Jun 5, 2023
1020ee7
import NonNull
PROGrand Jun 5, 2023
c31a502
NonNull
PROGrand Jun 5, 2023
dc0620e
Merge branch 'main' into main
PROGrand Jun 5, 2023
d185de2
Update CHANGELOG and Version
PROGrand Jun 5, 2023
a1fe134
interface version
PROGrand Jun 5, 2023
58aa61d
flutter_plugin_tools.dart make-deps-path-based
PROGrand Jun 5, 2023
ecae539
temporary publish_to: none
PROGrand Jun 5, 2023
2eb0657
temporary deps change: avoid The following unexpected non-local depen…
PROGrand Jun 5, 2023
a3f9c1d
deps order
PROGrand Jun 5, 2023
0d3d0a9
Merge branch 'main' into main
PROGrand Jun 5, 2023
076110f
mistype
PROGrand Jun 5, 2023
ce05518
args package changed.
PROGrand Jun 5, 2023
618a432
args changed: errorHandler
PROGrand Jun 5, 2023
e81dfee
args updated
PROGrand Jun 5, 2023
c95b6d5
bump dart version
PROGrand Jun 5, 2023
e392d1d
args: ^2.3.2
PROGrand Jun 5, 2023
72233fc
workaround args version
PROGrand Jun 5, 2023
0a81ffe
workaround args version
PROGrand Jun 5, 2023
8b0c6e8
merged
PROGrand Jun 5, 2023
dfe7b5a
dependency overrides
PROGrand Jun 6, 2023
277d4ae
Merge remote-tracking branch 'upstream/main'
PROGrand Jun 6, 2023
863f79a
examples deps
PROGrand Jun 6, 2023
3bdf221
examples deps
PROGrand Jun 6, 2023
6060603
packages deps
PROGrand Jun 6, 2023
ca7e7c6
publish_to: none removed
PROGrand Jun 6, 2023
5146a65
examples deps
PROGrand Jun 6, 2023
4e881fd
removed host deps
PROGrand Jun 6, 2023
4f07db2
camera deps
PROGrand Jun 6, 2023
a707e48
camera deps
PROGrand Jun 6, 2023
d50992d
camera deps
PROGrand Jun 6, 2023
fb99586
camera deps
PROGrand Jun 6, 2023
a0ca63a
around dependabot
PROGrand Jun 6, 2023
59186e6
merged
PROGrand Jun 21, 2023
0653456
changelogs updated
PROGrand Jun 21, 2023
0cb06da
MediaSettings export from camera/camera.dart
PROGrand Jun 21, 2023
2cc95af
camera/camera_controller.dart restored resolutionPreset and enableAudio
PROGrand Jun 21, 2023
22656de
Update packages/camera/camera/lib/src/camera_controller.dart
PROGrand Jun 21, 2023
1401590
Update packages/camera/camera_platform_interface/lib/src/types/media_…
PROGrand Jun 21, 2023
0ed67df
Update packages/camera/camera_platform_interface/lib/src/types/media_…
PROGrand Jun 21, 2023
c24d21e
Merge branch 'main' into main
PROGrand Jun 21, 2023
ff29e3f
version fix
PROGrand Jun 21, 2023
fdd75fd
Merge branch 'main' into main
PROGrand Jun 22, 2023
85a49f1
merged latest main 07/25/2023
PROGrand Jul 25, 2023
7088c8a
Object.hash
PROGrand Jul 25, 2023
85d6f20
bump gradle version moved to last entry changelog entry
PROGrand Jul 25, 2023
597dcc2
fixed format and analyzer issues
PROGrand Jul 25, 2023
c1bac8b
reverted merge for onStreamedFrameAvailable test
PROGrand Jul 25, 2023
8a90eee
Merge branch 'main' into main
PROGrand Jul 26, 2023
d7bc0be
camsim99 requests to remove gradle upgrade
PROGrand Aug 4, 2023
ea1777a
added safety checks for preview.
PROGrand Aug 4, 2023
e0ffa44
merged 08/04/2023
PROGrand Aug 4, 2023
f80e65f
Merge branch 'main' of github.com:mtbo-org/packages
PROGrand Aug 4, 2023
8e14f0d
version check
PROGrand Aug 4, 2023
aa4802e
merged
PROGrand Aug 14, 2023
ea9e49e
merged
PROGrand Aug 14, 2023
aa6cc8b
Update packages/camera/camera_android/CHANGELOG.md
PROGrand Aug 15, 2023
8d5a701
[file_selector] Fix default accept types on iOS (#4691)
stuartmorgan Aug 14, 2023
97abc1b
merged
PROGrand Aug 15, 2023
2d7ec3d
7.3.0
PROGrand Aug 15, 2023
def599e
7.4.2
PROGrand Aug 15, 2023
0b5d0ac
Merge branch 'main' into main
PROGrand Aug 15, 2023
d2dd528
merged with upstream/main (CHANGELOGs and package versions)
PROGrand Sep 4, 2023
14993b5
yaml: topics
PROGrand Sep 4, 2023
18be71c
touch
PROGrand Sep 4, 2023
b144466
Update packages/camera/camera_web/lib/src/camera.dart
PROGrand Sep 19, 2023
c7140d5
Update packages/camera/camera_web/lib/src/camera_service.dart
PROGrand Sep 19, 2023
81d3ba9
merged
PROGrand Sep 19, 2023
541b307
tested
PROGrand Sep 19, 2023
9776de3
analyzed
PROGrand Sep 19, 2023
a1bf2a0
audio bitrate constraints removed from test
PROGrand Sep 19, 2023
25e2241
Update packages/camera/camera_web/lib/src/camera_service.dart
PROGrand Sep 20, 2023
6fd3f07
Update packages/camera/camera_web/lib/src/camera.dart
PROGrand Sep 20, 2023
8204c5c
Merge branch 'main' into main
PROGrand Sep 20, 2023
ca0cc6b
applied suggestions
PROGrand Sep 20, 2023
cc6a0bd
Merge branch 'main' into main
PROGrand Sep 21, 2023
5cf735d
Merge branch 'main' into main
PROGrand Sep 22, 2023
59f3464
Merge branch 'main' into main
PROGrand Sep 24, 2023
5d0d68c
merged
PROGrand Sep 27, 2023
14ce07f
merged 09/30/2023
PROGrand Sep 30, 2023
d04448b
Merge branch 'main' into main
PROGrand Oct 2, 2023
835ce37
merged: camera_platform_interface
PROGrand Oct 24, 2023
556133e
actualized
PROGrand Oct 24, 2023
ee7d582
Merge remote-tracking branch 'refs/remotes/upstream/main'
PROGrand Apr 6, 2024
0b5da81
dart 3.2.3, merged with main.
PROGrand Apr 6, 2024
b892a0e
merged with upstream/main
PROGrand Apr 6, 2024
5665dea
removed cast
PROGrand Apr 6, 2024
bed9858
Merge branch 'main' into main
PROGrand Apr 7, 2024
4a6d0d7
Merge branch 'main' into main
PROGrand Apr 8, 2024
6ff11f7
remove exessive changes
PROGrand Apr 8, 2024
fb71469
Merge branch 'main' of github.com:mtbo-org/packages
PROGrand Apr 8, 2024
d711155
camera preview bug splitted into issue 146424
PROGrand Apr 8, 2024
1f92fe1
tested
PROGrand Apr 8, 2024
ad5acc3
README snipped validated
PROGrand Apr 8, 2024
b91875a
Merge branch 'main' into main
PROGrand Apr 8, 2024
f278395
Merge branch 'main' into main
PROGrand Apr 8, 2024
5be4485
Merge branch 'main' into main
PROGrand Apr 9, 2024
672877f
Merge branch 'main' into main
PROGrand Apr 9, 2024
21d838f
Merge branch 'main' into main
PROGrand Apr 10, 2024
def04ca
Merge branch 'main' into main
PROGrand Apr 11, 2024
3cfce50
Merge branch 'main' into main
PROGrand Apr 17, 2024
0af2d84
Merge branch 'main' into main
PROGrand Apr 17, 2024
05ce99c
suggestions applied
PROGrand Apr 17, 2024
8569ed4
Merge branch 'main' into main
PROGrand Apr 17, 2024
dd03971
Merge branch 'main' into main
PROGrand Apr 19, 2024
61d64ca
CameraController.withSettings -> CameraController
PROGrand Apr 19, 2024
7ac9609
Merge branch 'main' into main
PROGrand Apr 19, 2024
2639989
Merge branch 'main' into main
PROGrand Apr 20, 2024
ccceded
Merge branch 'main' into main
PROGrand Apr 22, 2024
86bfe6c
Merge branch 'main' into main
PROGrand Apr 22, 2024
5cb9ef3
Merge branch 'main' into main
PROGrand Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.5+3

* CameraPlatform.createCameraWithSettings to allow recorded video fps and bitrate control.
PROGrand marked this conversation as resolved.
Show resolved Hide resolved

## 0.10.5+2

* Fixes unawaited_futures violations.
Expand All @@ -12,6 +16,7 @@

## 0.10.4

* Adds support to control video fps and bitrate.
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
* Allows camera to be switched while video recording.
* Updates minimum Flutter version to 3.3.
* Aligns Dart and Flutter SDK constraints.
Expand Down
12 changes: 11 additions & 1 deletion packages/camera/camera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Here is a small example flutter app displaying a full screen camera preview.
<?code-excerpt "readme_full_example.dart (FullAppExample)"?>
```dart
import 'package:camera/camera.dart';
import 'package:camera_platform_interface/camera_platform_interface.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want to require a user to import the platform interface package. You should export MediaSettings in lib/camera.dart.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exported. Removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is still here.

import 'package:flutter/material.dart';

late List<CameraDescription> _cameras;
Expand All @@ -126,7 +127,16 @@ class _CameraAppState extends State<CameraApp> {
@override
void initState() {
super.initState();
controller = CameraController(_cameras[0], ResolutionPreset.max);
controller = CameraController.withSettings(
_cameras[0],
mediaSettings: const MediaSettings(
resolutionPreset: ResolutionPreset.low,
fps: 15,
videoBitrate: 200000,
audioBitrate: 32000,
enableAudio: true,
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
),
);
controller.initialize().then((_) {
if (!mounted) {
return;
Expand Down
47 changes: 34 additions & 13 deletions packages/camera/camera/example/integration_test/camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';
import 'dart:ui';

import 'package:camera/camera.dart';
import 'package:camera_platform_interface/camera_platform_interface.dart';
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
Expand Down Expand Up @@ -80,8 +81,12 @@ void main() {
bool previousPresetExactlySupported = true;
for (final MapEntry<ResolutionPreset, Size> preset
in presetExpectedSizes.entries) {
final CameraController controller =
CameraController(cameraDescription, preset.key);
final CameraController controller = CameraController.withSettings(
cameraDescription,
mediaSettings: MediaSettings(
resolutionPreset: preset.key,
),
);
await controller.initialize();
final bool presetExactlySupported =
await testCaptureImageResolution(controller, preset.key);
Expand Down Expand Up @@ -132,8 +137,12 @@ void main() {
bool previousPresetExactlySupported = true;
for (final MapEntry<ResolutionPreset, Size> preset
in presetExpectedSizes.entries) {
final CameraController controller =
CameraController(cameraDescription, preset.key);
final CameraController controller = CameraController.withSettings(
cameraDescription,
mediaSettings: MediaSettings(
resolutionPreset: preset.key,
),
);
await controller.initialize();
await controller.prepareForVideoRecording();
final bool presetExactlySupported =
Expand All @@ -155,10 +164,14 @@ void main() {
return;
}

final CameraController controller = CameraController(
final CameraController controller = CameraController.withSettings(
cameras[0],
ResolutionPreset.low,
enableAudio: false,
mediaSettings: const MediaSettings(
resolutionPreset: ResolutionPreset.low,
fps: 15,
videoBitrate: 200000,
audioBitrate: 32000,
),
);

await controller.initialize();
Expand Down Expand Up @@ -210,10 +223,14 @@ void main() {
return;
}

final CameraController controller = CameraController(
final CameraController controller = CameraController.withSettings(
cameras[0],
ResolutionPreset.low,
enableAudio: false,
mediaSettings: const MediaSettings(
resolutionPreset: ResolutionPreset.low,
fps: 15,
videoBitrate: 200000,
audioBitrate: 32000,
),
);

await controller.initialize();
Expand Down Expand Up @@ -242,10 +259,14 @@ void main() {
/// Start streaming with specifying the ImageFormatGroup.
Future<CameraImage> startStreaming(List<CameraDescription> cameras,
ImageFormatGroup? imageFormatGroup) async {
final CameraController controller = CameraController(
final CameraController controller = CameraController.withSettings(
cameras.first,
ResolutionPreset.low,
enableAudio: false,
mediaSettings: const MediaSettings(
resolutionPreset: ResolutionPreset.low,
fps: 15,
videoBitrate: 200000,
audioBitrate: 32000,
),
imageFormatGroup: imageFormatGroup,
);

Expand Down
12 changes: 9 additions & 3 deletions packages/camera/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:io';

import 'package:camera/camera.dart';
import 'package:camera_platform_interface/camera_platform_interface.dart';
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
Expand Down Expand Up @@ -637,10 +638,15 @@ class _CameraExampleHomeState extends State<CameraExampleHome>

Future<void> _initializeCameraController(
CameraDescription cameraDescription) async {
final CameraController cameraController = CameraController(
final CameraController cameraController = CameraController.withSettings(
cameraDescription,
kIsWeb ? ResolutionPreset.max : ResolutionPreset.medium,
enableAudio: enableAudio,
mediaSettings: MediaSettings(
resolutionPreset: ResolutionPreset.low,
fps: 15,
videoBitrate: 200000,
audioBitrate: 32000,
enableAudio: enableAudio,
),
imageFormatGroup: ImageFormatGroup.jpeg,
);

Expand Down
12 changes: 11 additions & 1 deletion packages/camera/camera/example/lib/readme_full_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// #docregion FullAppExample
import 'package:camera/camera.dart';
import 'package:camera_platform_interface/camera_platform_interface.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

import 'package:flutter/material.dart';

late List<CameraDescription> _cameras;
Expand All @@ -30,7 +31,16 @@ class _CameraAppState extends State<CameraApp> {
@override
void initState() {
super.initState();
controller = CameraController(_cameras[0], ResolutionPreset.max);
controller = CameraController.withSettings(
_cameras[0],
mediaSettings: const MediaSettings(
resolutionPreset: ResolutionPreset.low,
fps: 15,
videoBitrate: 200000,
audioBitrate: 32000,
enableAudio: true,
),
);
controller.initialize().then((_) {
if (!mounted) {
return;
Expand Down
12 changes: 7 additions & 5 deletions packages/camera/camera/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ environment:

dependencies:
camera:
# When depending on this package from a real application you should use:
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
# camera: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
camera_platform_interface:
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
path: ../../camera_platform_interface
flutter:
sdk: flutter
path_provider: ^2.0.0
Expand All @@ -30,3 +27,8 @@ dev_dependencies:

flutter:
uses-material-design: true

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins
dependency_overrides:
{camera: {path: ../../../camera/camera}, camera_android: {path: ../../../camera/camera_android}, camera_avfoundation: {path: ../../../camera/camera_avfoundation}, camera_platform_interface: {path: ../../../camera/camera_platform_interface}, camera_web: {path: ../../../camera/camera_web}}
35 changes: 21 additions & 14 deletions packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,33 @@ class CameraValue {
/// To show the camera preview on the screen use a [CameraPreview] widget.
class CameraController extends ValueNotifier<CameraValue> {
/// Creates a new camera controller in an uninitialized state.
/// Deprecated, use [withSettings].
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you not deprecating this to avoid a breaking change? Not sure if it's worth leaving this comment if it's not actually deprecated. Will defer to the reviewer of camera/camera though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, commented as deprecated to avoid breaking changes. According to https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages
...
image
...

PROGrand marked this conversation as resolved.
Show resolved Hide resolved
CameraController(
CameraDescription description,
this.resolutionPreset, {
this.enableAudio = true,
ResolutionPreset resolutionPreset, {
bool enableAudio = true,
this.imageFormatGroup,
}) : mediaSettings = MediaSettings(
resolutionPreset: resolutionPreset, enableAudio: enableAudio),
super(CameraValue.uninitialized(description));
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 remember correctly, you should be able to use the this.withSettings passthrough.

CameraController(
    CameraDescription description,
    this.resolutionPreset, {
    this.enableAudio = true,
    ResolutionPreset resolutionPreset, {
    bool enableAudio = true,
    this.imageFormatGroup,
  })  : this.withSettings(description, mediaSettings: MediaSettings(
            resolutionPreset: resolutionPreset, enableAudio: enableAudio), imageFormatGroup: imageFormatGroup);

Copy link
Contributor

Choose a reason for hiding this comment

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

This hasn't been addressed.


/// Creates a new camera controller in an uninitialized state, using specified media settings like fps and bitrate.
CameraController.withSettings(
CameraDescription description, {
this.mediaSettings,
this.imageFormatGroup,
}) : super(CameraValue.uninitialized(description));

/// The properties of the camera device controlled by this controller.
CameraDescription get description => value.description;

/// The resolution this controller is targeting.
/// The media settings this controller is targeting.
///
/// This resolution preset is not guaranteed to be available on the device,
/// This media settings are not guaranteed to be available on the device,
/// if unavailable a lower resolution will be used.
///
/// See also: [ResolutionPreset].
final ResolutionPreset resolutionPreset;
PROGrand marked this conversation as resolved.
Show resolved Hide resolved

/// Whether to include audio when recording a video.
final bool enableAudio;
/// See also: [MediaSettings].
final MediaSettings? mediaSettings;
PROGrand marked this conversation as resolved.
Show resolved Hide resolved

/// The [ImageFormatGroup] describes the output of the raw image format.
///
Expand Down Expand Up @@ -306,10 +313,9 @@ class CameraController extends ValueNotifier<CameraValue> {
);
});

_cameraId = await CameraPlatform.instance.createCamera(
_cameraId = await CameraPlatform.instance.createCameraWithSettings(
description,
resolutionPreset,
enableAudio: enableAudio,
mediaSettings,
);

_unawaited(CameraPlatform.instance
Expand Down Expand Up @@ -365,9 +371,10 @@ class CameraController extends ValueNotifier<CameraValue> {

/// Pauses the current camera preview
Future<void> pausePreview() async {
if (value.isPreviewPaused) {
if (value.isPreviewPaused || !value.isInitialized || _isDisposed) {
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
return;
}

try {
await CameraPlatform.instance.pausePreview(_cameraId);
value = value.copyWith(
Expand Down Expand Up @@ -640,7 +647,7 @@ class CameraController extends ValueNotifier<CameraValue> {
///
/// The supplied [zoom] value should be between 1.0 and the maximum supported
/// zoom level returned by the `getMaxZoomLevel`. Throws an `CameraException`
/// when an illegal zoom level is suplied.
/// when an illegal zoom level is supplied.
Future<void> setZoomLevel(double zoom) {
_throwIfNotInitialized('setZoomLevel');
try {
Expand Down
5 changes: 3 additions & 2 deletions packages/camera/camera/lib/src/camera_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CameraPreview extends StatelessWidget {

@override
Widget build(BuildContext context) {
return controller.value.isInitialized
return (controller.value.isInitialized && !controller.value.isPreviewPaused)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this a fix for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use camera package intensively and there was error on closing widgets with mounted camera preview.
Actually controller.value.isInitialized is not enough, because const CameraValue.uninitialized() is never called. And isInitialized remains true even on disposed controller.
In scenarios with controller disposed in didChangeAppLifecycleState: the isPreviewPaused is the only flag giving a clue to stop previewing and even listening to controller.value changes is not necessary if preview is not (already not) required.

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 understand correctly, you added this to check if the controller is disposed. It is probably better to add a isDisposed method to the CameraController instead. Although I'm not entirely sure why we added a debugCheckIsDisposed instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bump on this discussion.

? ValueListenableBuilder<CameraValue>(
valueListenable: controller,
builder: (BuildContext context, Object? value, Widget? child) {
Expand All @@ -32,7 +32,8 @@ class CameraPreview extends StatelessWidget {
child: Stack(
fit: StackFit.expand,
children: <Widget>[
_wrapInRotatedBox(child: controller.buildPreview()),
if (!controller.value.isPreviewPaused)
_wrapInRotatedBox(child: controller.buildPreview()),
child ?? Container(),
],
),
Expand Down
26 changes: 21 additions & 5 deletions packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.10.5+2
version: 0.10.5+3
PROGrand marked this conversation as resolved.
Show resolved Hide resolved

environment:
sdk: ">=2.18.0 <4.0.0"
Expand All @@ -21,10 +21,11 @@ flutter:
default_package: camera_web

dependencies:
camera_android: ^0.10.7
camera_avfoundation: ^0.9.13
camera_platform_interface: ^2.5.0
camera_web: ^0.3.1
camera_android: ^0.10.8+2
camera_avfoundation: ^0.9.13+2
camera_platform_interface: ^2.5.1
camera_web: ^0.3.1+4

flutter:
sdk: flutter
flutter_plugin_android_lifecycle: ^2.0.2
Expand All @@ -38,3 +39,18 @@ dev_dependencies:
mockito: 5.4.1
plugin_platform_interface: ^2.0.0
video_player: ^2.0.0

# TODO: for PR

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
# See https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins
dependency_overrides:

camera_android:
path: ../../camera/camera_android
camera_avfoundation:
path: ../../camera/camera_avfoundation
camera_platform_interface:
path: ../../camera/camera_platform_interface
camera_web:
path: ../../camera/camera_web