@@ -253,7 +253,7 @@ class CameraPickerState extends State<CameraPicker>
253
253
254
254
/// Available cameras.
255
255
/// 可用的相机实例
256
- late final List <CameraDescription > cameras;
256
+ late List <CameraDescription > cameras;
257
257
258
258
/// Current exposure offset.
259
259
/// 当前曝光值
@@ -763,16 +763,16 @@ class CameraPickerState extends State<CameraPicker>
763
763
/// 将被取消,并且状态会重置。
764
764
void recordDetectionCancel (PointerUpEvent event) {
765
765
_recordDetectTimer? .cancel ();
766
- if (controller.value.isRecordingVideo) {
767
- _lastShootingButtonPressedPosition = null ;
768
- stopRecordingVideo ();
769
- safeSetState (() {});
770
- }
771
766
if (isShootingButtonAnimate) {
772
767
safeSetState (() {
773
768
isShootingButtonAnimate = false ;
774
769
});
775
770
}
771
+ if (controller.value.isRecordingVideo) {
772
+ _lastShootingButtonPressedPosition = null ;
773
+ safeSetState (() {});
774
+ stopRecordingVideo ();
775
+ }
776
776
}
777
777
778
778
/// Set record file path and start recording.
@@ -790,8 +790,10 @@ class CameraPickerState extends State<CameraPicker>
790
790
realDebugPrint ('Error when start recording video: $e ' );
791
791
if (controller.value.isRecordingVideo) {
792
792
controller.stopVideoRecording ().catchError ((Object e) {
793
- realDebugPrint ('Error when stop recording video: $e ' );
794
- throw e;
793
+ realDebugPrint (
794
+ 'Error when stop recording video after an error start: $e ' ,
795
+ );
796
+ stopRecordingVideo ();
795
797
});
796
798
}
797
799
throw e;
@@ -802,6 +804,12 @@ class CameraPickerState extends State<CameraPicker>
802
804
/// Stop the recording process.
803
805
/// 停止录制视频
804
806
Future <void > stopRecordingVideo () async {
807
+ void _handleError () {
808
+ _recordCountdownTimer? .cancel ();
809
+ isShootingButtonAnimate = false ;
810
+ safeSetState (() {});
811
+ }
812
+
805
813
if (controller.value.isRecordingVideo) {
806
814
controller.stopVideoRecording ().then ((XFile file) async {
807
815
final AssetEntity ? entity = await CameraPickerViewer .pushToViewer (
@@ -814,16 +822,20 @@ class CameraPickerState extends State<CameraPicker>
814
822
);
815
823
if (entity != null ) {
816
824
Navigator .of (context).pop (entity);
817
- } else {
818
- safeSetState (() {});
819
825
}
820
826
}).catchError ((Object e) {
821
827
realDebugPrint ('Error when stop recording video: $e ' );
828
+ realDebugPrint ('Try to initialize a new CameraController...' );
829
+ initCameras ();
830
+ _handleError ();
822
831
throw e;
823
832
}).whenComplete (() {
824
833
isShootingButtonAnimate = false ;
834
+ safeSetState (() {});
825
835
});
836
+ return ;
826
837
}
838
+ _handleError ();
827
839
}
828
840
829
841
////////////////////////////////////////////////////////////////////////////
0 commit comments