@@ -232,12 +232,30 @@ class CameraValue {
232
232
/// To show the camera preview on the screen use a [CameraPreview] widget.
233
233
class CameraController extends ValueNotifier <CameraValue > {
234
234
/// Creates a new camera controller in an uninitialized state.
235
+ ///
236
+ /// - [resolutionPreset] affect the quality of video recording and image capture.
237
+ /// - [enableAudio] controls audio presence in recorded video.
238
+ ///
239
+ /// Following parameters (if present) will overwrite [resolutionPreset] settings:
240
+ /// - [fps] controls rate at which frames should be captured by the camera in frames per second.
241
+ /// - [videoBitrate] controls the video encoding bit rate for recording.
242
+ /// - [audioBitrate] controls the audio encoding bit rate for recording.
243
+
235
244
CameraController (
236
245
CameraDescription description,
237
- this .resolutionPreset, {
238
- this .enableAudio = true ,
246
+ ResolutionPreset resolutionPreset, {
247
+ bool enableAudio = true ,
248
+ int ? fps,
249
+ int ? videoBitrate,
250
+ int ? audioBitrate,
239
251
this .imageFormatGroup,
240
- }) : super (CameraValue .uninitialized (description));
252
+ }) : mediaSettings = MediaSettings (
253
+ resolutionPreset: resolutionPreset,
254
+ enableAudio: enableAudio,
255
+ fps: fps,
256
+ videoBitrate: videoBitrate,
257
+ audioBitrate: audioBitrate),
258
+ super (CameraValue .uninitialized (description));
241
259
242
260
/// The properties of the camera device controlled by this controller.
243
261
CameraDescription get description => value.description;
@@ -248,10 +266,19 @@ class CameraController extends ValueNotifier<CameraValue> {
248
266
/// if unavailable a lower resolution will be used.
249
267
///
250
268
/// See also: [ResolutionPreset] .
251
- final ResolutionPreset resolutionPreset;
269
+ ResolutionPreset get resolutionPreset =>
270
+ mediaSettings.resolutionPreset ?? ResolutionPreset .max;
252
271
253
272
/// Whether to include audio when recording a video.
254
- final bool enableAudio;
273
+ bool get enableAudio => mediaSettings.enableAudio;
274
+
275
+ /// The media settings this controller is targeting.
276
+ ///
277
+ /// This media settings are not guaranteed to be available on the device,
278
+ /// if unavailable a [resolutionPreset] default values will be used.
279
+ ///
280
+ /// See also: [MediaSettings] .
281
+ final MediaSettings mediaSettings;
255
282
256
283
/// The [ImageFormatGroup] describes the output of the raw image format.
257
284
///
@@ -265,6 +292,7 @@ class CameraController extends ValueNotifier<CameraValue> {
265
292
266
293
bool _isDisposed = false ;
267
294
StreamSubscription <CameraImageData >? _imageStreamSubscription;
295
+
268
296
// A Future awaiting an attempt to initialize (e.g. after `initialize` was
269
297
// just called). If the controller has not been initialized at least once,
270
298
// this value is null.
@@ -313,10 +341,9 @@ class CameraController extends ValueNotifier<CameraValue> {
313
341
);
314
342
});
315
343
316
- _cameraId = await CameraPlatform .instance.createCamera (
344
+ _cameraId = await CameraPlatform .instance.createCameraWithSettings (
317
345
description,
318
- resolutionPreset,
319
- enableAudio: enableAudio,
346
+ mediaSettings,
320
347
);
321
348
322
349
_unawaited (CameraPlatform .instance
@@ -372,7 +399,7 @@ class CameraController extends ValueNotifier<CameraValue> {
372
399
373
400
/// Pauses the current camera preview
374
401
Future <void > pausePreview () async {
375
- if (value.isPreviewPaused) {
402
+ if (value.isPreviewPaused || ! value.isInitialized || _isDisposed ) {
376
403
return ;
377
404
}
378
405
try {
@@ -923,7 +950,7 @@ class Optional<T> extends IterableBase<T> {
923
950
if (_value == null ) {
924
951
throw StateError ('value called on absent Optional.' );
925
952
}
926
- return _value! ;
953
+ return _value;
927
954
}
928
955
929
956
/// Executes a function if the Optional value is present.
@@ -960,7 +987,7 @@ class Optional<T> extends IterableBase<T> {
960
987
Optional <S > transform <S >(S Function (T value) transformer) {
961
988
return _value == null
962
989
? Optional <S >.absent ()
963
- : Optional <S >.of (transformer (_value as T ));
990
+ : Optional <S >.of (transformer (_value));
964
991
}
965
992
966
993
/// Transforms the Optional value.
@@ -971,7 +998,7 @@ class Optional<T> extends IterableBase<T> {
971
998
Optional <S > transformNullable <S >(S ? Function (T value) transformer) {
972
999
return _value == null
973
1000
? Optional <S >.absent ()
974
- : Optional <S >.fromNullable (transformer (_value as T ));
1001
+ : Optional <S >.fromNullable (transformer (_value));
975
1002
}
976
1003
977
1004
@override
0 commit comments