-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Changes from 22 commits
f294625
5ca79b9
e08e046
21617de
59d66d3
aeec92e
869b787
3cf6030
6ac763e
a40177a
fea1fc7
9f71f8d
4a0ac77
8fcf1ae
da4ecd8
16645ef
d7dea54
6caea7e
4bec8f3
11b43c1
772e011
dbb752d
7f01b93
3506af1
8f95dc2
6b1f96c
6f97b51
d96f9d5
401adce
8edd212
0a8fe17
d072dfb
accef7c
480761c
bdd74a8
ec5856f
6736802
9fdd1e0
8a55d87
7d88b16
86c95e9
c78cfc5
5597838
d006820
f60804d
d21dd5b
b08f5f1
d361800
a29b222
1020ee7
c31a502
dc0620e
d185de2
a1fe134
58aa61d
ecae539
2eb0657
a3f9c1d
0d3d0a9
076110f
ce05518
618a432
e81dfee
c95b6d5
e392d1d
72233fc
0a81ffe
8b0c6e8
dfe7b5a
277d4ae
863f79a
3bdf221
6060603
ca7e7c6
5146a65
4e881fd
4f07db2
a707e48
d50992d
fb99586
a0ca63a
59186e6
0653456
0cb06da
2cc95af
22656de
1401590
0ed67df
c24d21e
ff29e3f
fdd75fd
85a49f1
7088c8a
85d6f20
597dcc2
c1bac8b
8a90eee
d7bc0be
ea1777a
e0ffa44
f80e65f
8e14f0d
aa4802e
ea9e49e
aa6cc8b
8d5a701
97abc1b
2d7ec3d
def599e
0b5d0ac
d2dd528
14993b5
18be71c
b144466
c7140d5
81d3ba9
541b307
9776de3
a1bf2a0
25e2241
6fd3f07
8204c5c
ca0cc6b
cc6a0bd
5cf735d
59f3464
5d0d68c
14ce07f
d04448b
835ce37
556133e
ee7d582
0b5da81
b892a0e
5665dea
bed9858
4a6d0d7
6ff11f7
fb71469
d711155
1f92fe1
ad5acc3
b91875a
f278395
5be4485
672877f
21d838f
def04ca
3cfce50
0af2d84
05ce99c
8569ed4
dd03971
61d64ca
7ac9609
2639989
ccceded
86bfe6c
5cb9ef3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
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. We don't want to require a user to import the platform interface package. You should export MediaSettings in lib/camera.dart. 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. Exported. Removed. 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. This is still here. |
||
import 'package:flutter/material.dart'; | ||
|
||
late List<CameraDescription> _cameras; | ||
|
@@ -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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
// #docregion FullAppExample | ||
import 'package:camera/camera.dart'; | ||
import 'package:camera_platform_interface/camera_platform_interface.dart'; | ||
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. same here 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. Removed. 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. Same. |
||
import 'package:flutter/material.dart'; | ||
|
||
late List<CameraDescription> _cameras; | ||
|
@@ -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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,26 +224,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]. | ||
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. 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 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. Yes, commented as deprecated to avoid breaking changes. According to https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages
PROGrand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CameraController( | ||
this.description, | ||
this.resolutionPreset, { | ||
this.enableAudio = true, | ||
ResolutionPreset resolutionPreset, { | ||
bool enableAudio = true, | ||
this.imageFormatGroup, | ||
}) : mediaSettings = MediaSettings( | ||
resolutionPreset: resolutionPreset, enableAudio: enableAudio), | ||
super(const CameraValue.uninitialized()); | ||
|
||
/// Creates a new camera controller in an uninitialized state, using specified media settings like fps and bitrate. | ||
CameraController.withSettings( | ||
this.description, { | ||
this.mediaSettings, | ||
this.imageFormatGroup, | ||
}) : super(const CameraValue.uninitialized()); | ||
|
||
/// The properties of the camera device controlled by this controller. | ||
final CameraDescription 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. | ||
/// | ||
|
@@ -293,10 +300,9 @@ class CameraController extends ValueNotifier<CameraValue> { | |
); | ||
}); | ||
|
||
_cameraId = await CameraPlatform.instance.createCamera( | ||
_cameraId = await CameraPlatform.instance.createCameraWithSettings( | ||
description, | ||
resolutionPreset, | ||
enableAudio: enableAudio, | ||
mediaSettings, | ||
); | ||
|
||
_unawaited(CameraPlatform.instance | ||
|
@@ -351,9 +357,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( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ class CameraPreview extends StatelessWidget { | |
|
||
@override | ||
Widget build(BuildContext context) { | ||
return controller.value.isInitialized | ||
return (controller.value.isInitialized && !controller.value.isPreviewPaused) | ||
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. What is this a fix for? 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. We use camera package intensively and there was error on closing widgets with mounted camera preview. 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. If I understand correctly, you added this to check if the controller is disposed. It is probably better to add a 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. Bump on this discussion. |
||
? ValueListenableBuilder<CameraValue>( | ||
valueListenable: controller, | ||
builder: (BuildContext context, Object? value, Widget? child) { | ||
|
@@ -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(), | ||
], | ||
), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is adding a new feature, it should bump the minor version. (e.g.
0.10.4
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incremented minor