diff --git a/src/SopHelper.Avalonia/Training/CameraViewModel.cs b/src/SopHelper.Avalonia/Training/CameraViewModel.cs index d1fca5d..8d6cf30 100644 --- a/src/SopHelper.Avalonia/Training/CameraViewModel.cs +++ b/src/SopHelper.Avalonia/Training/CameraViewModel.cs @@ -1,4 +1,4 @@ -using System.Diagnostics; +using System.Diagnostics; using System.IO; using System.Text.Json; using Avalonia; @@ -71,6 +71,7 @@ public sealed partial class CameraViewModel : BindableBase public DelegateCommand PauseCommand { get; } public DelegateCommand RestartCommand { get; } public DelegateCommand PlayVideoCommand { get; } + public DelegateCommand PauseVideoCommand { get; } public DelegateCommand StopVideoCommand { get; } public DelegateCommand ImportVideoCommand { get; } public event Action? RecordingLimitReached; @@ -96,7 +97,8 @@ public sealed partial class CameraViewModel : BindableBase StopRecordingCommand = Command(() => { StopRecording(); return Task.CompletedTask; }, () => !IsBusy && !_closing && IsRecording); PauseCommand = Command(() => { TogglePause(); return Task.CompletedTask; }, () => !IsBusy && !_closing && IsRecording); RestartCommand = Command(RestartRecordingAsync, () => _sopStandard && !IsBusy && !_closing && !IsTestingFlow && HasStandardVideo && IsPreviewing && Preview != null && HasRecentFrame); - PlayVideoCommand = Command(ToggleVideoPlaybackAsync, () => _sopStandard && !IsBusy && !_closing && !IsTestingFlow && !IsRecording && HasStandardVideo); + PlayVideoCommand = Command(PlayVideoAsync, () => _sopStandard && !IsBusy && !_closing && !IsTestingFlow && !IsRecording && HasStandardVideo && !Playback.IsPlaying); + PauseVideoCommand = Command(() => { Playback.Pause(); Status = "视频播放已暂停"; return Task.CompletedTask; }, () => !IsBusy && !_closing && !IsTestingFlow && Playback.IsPlaying); ImportVideoCommand = Command(ImportVideoAsync, () => _sopStandard && !IsBusy && !_closing && !IsTestingFlow && !IsRecording); TestFlowCommand = Command(StartFlowTestAsync, () => _sopStandard && !IsBusy && !_closing && !IsTestingFlow && !IsRecording && HasStandardVideo && FlowTestConfigProvider is not null); StopVideoCommand = Command(async () => { await Playback.StopAsync(); EndFlowTest("测试已停止"); Status = "视频播放已停止"; }, () => !IsBusy && !_closing && Playback.IsLoaded); @@ -110,7 +112,7 @@ public sealed partial class CameraViewModel : BindableBase if (e.PropertyName == nameof(Playback.IsAtEnd) && Playback.IsAtEnd) { if (IsTestingFlow) _ = CompleteFlowTestAsync(); - Status = "视频播放结束,可点击“重新播放”再次观看"; + Status = "视频播放结束,可点击“播放”再次观看"; } }; Playback.Failed += message => { EndFlowTest(message); Status = message; }; @@ -190,11 +192,11 @@ public sealed partial class CameraViewModel : BindableBase _previewCamera = selected; IsPreviewing = true; Status = "相机预览中,可开始录像"; } - private async Task ToggleVideoPlaybackAsync() + private async Task PlayVideoAsync() { FlowTestRegions = null; if (IsRecording) throw new InvalidOperationException("请先停止录像并保存,再播放视频"); - if (Playback.IsPlaying) { Playback.Pause(); Status = "视频播放已暂停"; return; } + if (Playback.IsPlaying) return; if (IsPreviewing) { await Task.Run(_camera.Disconnect); diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml index 68f3cd5..86ddf94 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml @@ -107,10 +107,10 @@ - - + + @@ -122,23 +122,7 @@