-
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 149 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 |
---|---|---|
|
@@ -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], | ||
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 |
---|---|---|
|
@@ -234,8 +234,17 @@ class CameraController extends ValueNotifier<CameraValue> { | |
/// Creates a new camera controller in an uninitialized state. | ||
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)); | ||
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 remember correctly, you should be able to use the 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); 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 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)); | ||
|
||
|
@@ -248,10 +257,19 @@ class CameraController extends ValueNotifier<CameraValue> { | |
/// if unavailable a lower resolution will be used. | ||
/// | ||
/// See also: [ResolutionPreset]. | ||
final ResolutionPreset resolutionPreset; | ||
PROGrand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ResolutionPreset get resolutionPreset => | ||
mediaSettings.resolutionPreset ?? ResolutionPreset.max; | ||
|
||
/// Whether to include audio when recording a video. | ||
final bool enableAudio; | ||
bool get enableAudio => mediaSettings.enableAudio; | ||
|
||
/// The media settings this controller is targeting. | ||
/// | ||
/// This media settings are not guaranteed to be available on the device, | ||
/// if unavailable a lower resolution will be used. | ||
/// | ||
/// See also: [MediaSettings]. | ||
final MediaSettings mediaSettings; | ||
|
||
/// The [ImageFormatGroup] describes the output of the raw image format. | ||
/// | ||
|
@@ -265,6 +283,7 @@ class CameraController extends ValueNotifier<CameraValue> { | |
|
||
bool _isDisposed = false; | ||
StreamSubscription<CameraImageData>? _imageStreamSubscription; | ||
|
||
// A Future awaiting an attempt to initialize (e.g. after `initialize` was | ||
// just called). If the controller has not been initialized at least once, | ||
// this value is null. | ||
|
@@ -313,10 +332,9 @@ class CameraController extends ValueNotifier<CameraValue> { | |
); | ||
}); | ||
|
||
_cameraId = await CameraPlatform.instance.createCamera( | ||
_cameraId = await CameraPlatform.instance.createCameraWithSettings( | ||
description, | ||
resolutionPreset, | ||
enableAudio: enableAudio, | ||
mediaSettings, | ||
); | ||
|
||
_unawaited(CameraPlatform.instance | ||
|
@@ -372,7 +390,7 @@ 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 { | ||
|
@@ -923,7 +941,7 @@ class Optional<T> extends IterableBase<T> { | |
if (_value == null) { | ||
throw StateError('value called on absent Optional.'); | ||
} | ||
return _value!; | ||
return _value; | ||
} | ||
|
||
/// Executes a function if the Optional value is present. | ||
|
@@ -960,7 +978,7 @@ class Optional<T> extends IterableBase<T> { | |
Optional<S> transform<S>(S Function(T value) transformer) { | ||
return _value == null | ||
? Optional<S>.absent() | ||
: Optional<S>.of(transformer(_value as T)); | ||
: Optional<S>.of(transformer(_value)); | ||
} | ||
|
||
/// Transforms the Optional value. | ||
|
@@ -971,7 +989,7 @@ class Optional<T> extends IterableBase<T> { | |
Optional<S> transformNullable<S>(S? Function(T value) transformer) { | ||
return _value == null | ||
? Optional<S>.absent() | ||
: Optional<S>.fromNullable(transformer(_value as T)); | ||
: Optional<S>.fromNullable(transformer(_value)); | ||
} | ||
|
||
@override | ||
|
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is still here.