@@ -418,18 +418,26 @@ class CameraPickerState extends State<CameraPicker>
418
418
await newController.prepareForVideoRecording ();
419
419
}
420
420
// Then call other asynchronous methods.
421
- await Future .wait (< Future <void >> [
422
- if (config.lockCaptureOrientation != null )
423
- newController.lockCaptureOrientation (config.lockCaptureOrientation),
424
- (() async => _maxAvailableExposureOffset =
425
- await newController.getMaxExposureOffset ())(),
426
- (() async => _minAvailableExposureOffset =
427
- await newController.getMinExposureOffset ())(),
428
- (() async =>
429
- _maxAvailableZoom = await newController.getMaxZoomLevel ())(),
430
- (() async =>
431
- _minAvailableZoom = await newController.getMinZoomLevel ())(),
432
- ]);
421
+ await Future .wait (
422
+ < Future <void >> [
423
+ if (config.lockCaptureOrientation != null )
424
+ newController
425
+ .lockCaptureOrientation (config.lockCaptureOrientation),
426
+ newController
427
+ .getMinExposureOffset ()
428
+ .then ((double value) => _maxAvailableExposureOffset = value),
429
+ newController
430
+ .getMaxExposureOffset ()
431
+ .then ((double value) => _minAvailableExposureOffset = value),
432
+ newController
433
+ .getMaxZoomLevel ()
434
+ .then ((double value) => _maxAvailableZoom = value),
435
+ newController
436
+ .getMinZoomLevel ()
437
+ .then ((double value) => _minAvailableZoom = value),
438
+ ],
439
+ eagerError: true ,
440
+ );
433
441
_controller = newController;
434
442
} catch (e, s) {
435
443
handleErrorWithHandler (e, config.onError, s: s);
@@ -700,26 +708,34 @@ class CameraPickerState extends State<CameraPicker>
700
708
/// Set record file path and start recording.
701
709
/// 设置拍摄文件路径并开始录制视频
702
710
Future <void > startRecordingVideo () async {
703
- if (! controller.value.isRecordingVideo) {
704
- controller.startVideoRecording ().then ((dynamic _) {
705
- safeSetState (() {});
706
- if (isRecordingRestricted) {
707
- _recordCountdownTimer = Timer (maximumRecordingDuration! , () {
708
- stopRecordingVideo ();
709
- });
710
- }
711
- }).catchError ((Object e) {
712
- realDebugPrint ('Error when start recording video: $e ' );
713
- if (controller.value.isRecordingVideo) {
714
- controller.stopVideoRecording ().catchError ((Object e) {
715
- realDebugPrint (
716
- 'Error when stop recording video after an error start: $e ' ,
717
- );
718
- stopRecordingVideo ();
719
- });
720
- }
721
- handleErrorWithHandler (e, config.onError);
722
- });
711
+ if (controller.value.isRecordingVideo) {
712
+ return ;
713
+ }
714
+ try {
715
+ await controller.startVideoRecording ();
716
+ if (isRecordingRestricted) {
717
+ _recordCountdownTimer = Timer (maximumRecordingDuration! , () {
718
+ stopRecordingVideo ();
719
+ });
720
+ }
721
+ } catch (e, s) {
722
+ realDebugPrint ('Error when start recording video: $e ' );
723
+ if (! controller.value.isRecordingVideo) {
724
+ handleErrorWithHandler (e, config.onError, s: s);
725
+ return ;
726
+ }
727
+ try {
728
+ await controller.stopVideoRecording ();
729
+ } catch (e, s) {
730
+ realDebugPrint (
731
+ 'Error when stop recording video after an error start: $e ' ,
732
+ );
733
+ _recordCountdownTimer? .cancel ();
734
+ isShootingButtonAnimate = false ;
735
+ handleErrorWithHandler (e, config.onError, s: s);
736
+ }
737
+ } finally {
738
+ safeSetState (() {});
723
739
}
724
740
}
725
741
@@ -732,36 +748,36 @@ class CameraPickerState extends State<CameraPicker>
732
748
safeSetState (() {});
733
749
}
734
750
735
- if (controller.value.isRecordingVideo) {
736
- try {
737
- final XFile file = await controller.stopVideoRecording ();
738
- final bool ? isCapturedFileHandled = config.onXFileCaptured? .call (
739
- file,
740
- CameraPickerViewType .video,
741
- );
742
- if (isCapturedFileHandled ?? false ) {
743
- return ;
744
- }
745
- final AssetEntity ? entity = await _pushToViewer (
746
- file: file,
747
- viewType: CameraPickerViewType .video,
748
- );
749
- if (entity != null ) {
750
- Navigator .of (context).pop (entity);
751
- }
752
- } catch (e) {
753
- realDebugPrint ('Error when stop recording video: $e ' );
754
- realDebugPrint ('Try to initialize a new CameraController...' );
755
- initCameras ();
756
- _handleError ();
757
- handleErrorWithHandler (e, config.onError);
758
- } finally {
759
- isShootingButtonAnimate = false ;
760
- safeSetState (() {});
761
- }
751
+ if (! controller.value.isRecordingVideo) {
752
+ _handleError ();
762
753
return ;
763
754
}
764
- _handleError ();
755
+ try {
756
+ final XFile file = await controller.stopVideoRecording ();
757
+ final bool ? isCapturedFileHandled = config.onXFileCaptured? .call (
758
+ file,
759
+ CameraPickerViewType .video,
760
+ );
761
+ if (isCapturedFileHandled ?? false ) {
762
+ return ;
763
+ }
764
+ final AssetEntity ? entity = await _pushToViewer (
765
+ file: file,
766
+ viewType: CameraPickerViewType .video,
767
+ );
768
+ if (entity != null ) {
769
+ Navigator .of (context).pop (entity);
770
+ }
771
+ } catch (e, s) {
772
+ realDebugPrint ('Error when stop recording video: $e ' );
773
+ realDebugPrint ('Try to initialize a new CameraController...' );
774
+ initCameras ();
775
+ _handleError ();
776
+ handleErrorWithHandler (e, config.onError, s: s);
777
+ } finally {
778
+ isShootingButtonAnimate = false ;
779
+ safeSetState (() {});
780
+ }
765
781
}
766
782
767
783
Future <AssetEntity ?> _pushToViewer ({
0 commit comments