解决录制结束后,无法重新预览相机问题
This commit is contained in:
@@ -161,22 +161,31 @@ class RecordingPlatformHandler(
|
||||
controller.stopRecording { path ->
|
||||
RecordingSession.stopForeground(activity)
|
||||
DoNotDisturbHelper.disable(activity)
|
||||
mainHandler.post {
|
||||
val gallerySaved = path != null && controller.status.state != RecordingState.ERROR
|
||||
val payload =
|
||||
mutableMapOf<String, Any?>(
|
||||
"outputPath" to path,
|
||||
"status" to controller.status.toMap(),
|
||||
"gallerySaved" to gallerySaved,
|
||||
)
|
||||
if (!gallerySaved) {
|
||||
payload["galleryErrorMessage"] = controller.status.message ?: "保存到相册失败"
|
||||
}
|
||||
result.success(payload)
|
||||
val previewView = activity.recordingPreviewView
|
||||
if (previewView == null) {
|
||||
mainHandler.post { deliverStopResult(result, path) }
|
||||
return@stopRecording
|
||||
}
|
||||
controller.rebindForRecording(activity, previewView) { _ ->
|
||||
mainHandler.post { deliverStopResult(result, path) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun deliverStopResult(result: MethodChannel.Result, path: String?) {
|
||||
val gallerySaved = path != null && controller.status.state != RecordingState.ERROR
|
||||
val payload =
|
||||
mutableMapOf<String, Any?>(
|
||||
"outputPath" to path,
|
||||
"status" to controller.status.toMap(),
|
||||
"gallerySaved" to gallerySaved,
|
||||
)
|
||||
if (!gallerySaved) {
|
||||
payload["galleryErrorMessage"] = controller.status.message ?: "保存到相册失败"
|
||||
}
|
||||
result.success(payload)
|
||||
}
|
||||
|
||||
private fun setImmersiveMode(enabled: Boolean) {
|
||||
val window = activity.window
|
||||
WindowCompat.setDecorFitsSystemWindows(window, !enabled)
|
||||
|
||||
@@ -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