解决录制结束后,无法重新预览相机问题
This commit is contained in:
@@ -196,6 +196,32 @@ class RecordingViewModel extends Notifier<RecordingModel> {
|
||||
throw StateError('initializePreview retry exhausted');
|
||||
}
|
||||
|
||||
/// 停止录制后重新绑定相机预览(重置 isPreviewReady 以显示加载遮罩)。
|
||||
Future<void> restorePreview() async {
|
||||
if (!RecordingPlatform.isSupported) return;
|
||||
|
||||
_updateSession((s) => s.copyWith(isPreviewReady: false, errorMessage: null));
|
||||
try {
|
||||
final status = await _initializePreviewWithRetry();
|
||||
_updateSession(
|
||||
(s) => s.copyWith(
|
||||
status: status,
|
||||
isPreviewReady: status.state == RecordingState.previewing,
|
||||
errorMessage: status.state == RecordingState.previewing
|
||||
? null
|
||||
: (status.message ?? '相机预览初始化失败'),
|
||||
),
|
||||
);
|
||||
} on PlatformException catch (error) {
|
||||
_updateSession(
|
||||
(s) => s.copyWith(
|
||||
isPreviewReady: false,
|
||||
errorMessage: error.message ?? '相机预览初始化失败',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<Permission> _galleryPermissions() {
|
||||
if (Platform.isIOS) {
|
||||
return [Permission.photosAddOnly, Permission.photos];
|
||||
@@ -280,6 +306,8 @@ class RecordingViewModel extends Notifier<RecordingModel> {
|
||||
_updateSession(
|
||||
(s) => s.copyWith(errorMessage: error.message ?? '停止录制失败'),
|
||||
);
|
||||
} finally {
|
||||
await restorePreview();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user