stopRecordingVideo method
Stop the recording process. 停止录制视频
Implementation
Future<void> stopRecordingVideo() async {
void handleError() {
recordCountdownTimer?.cancel();
isShootingButtonAnimate = false;
safeSetState(() {});
}
recordStopwatch.stop();
if (!controller.value.isRecordingVideo) {
handleError();
return;
}
safeSetState(() {
isShootingButtonAnimate = false;
});
try {
final XFile file = await controller.stopVideoRecording();
if (recordStopwatch.elapsed < minimumRecordingDuration) {
pickerConfig.onMinimumRecordDurationNotMet?.call();
return;
}
await controller.pausePreview();
final bool? isCapturedFileHandled = pickerConfig.onXFileCaptured?.call(
file,
CameraPickerViewType.video,
);
if (isCapturedFileHandled ?? false) {
return;
}
final AssetEntity? entity = await pushToViewer(
file: file,
viewType: CameraPickerViewType.video,
);
if (entity != null) {
Navigator.of(context).pop(entity);
} else {
await controller.resumePreview();
}
} catch (e, s) {
realDebugPrint('Error when stop recording video: $e');
realDebugPrint('Try to initialize a new CameraController...');
initCameras();
handleError();
handleErrorWithHandler(e, pickerConfig.onError, s: s);
} finally {
safeSetState(() {});
}
}