分离视频播放暂停按钮并将步骤页视频区域调整为半窗
This commit is contained in:
parent
f561e91ce6
commit
6ab9be708d
@ -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<string>? 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);
|
||||
|
||||
@ -107,10 +107,10 @@
|
||||
<TabItem Header="步骤">
|
||||
<Grid Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="270" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="330" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid RowDefinitions="180,*" Margin="0,0,6,0">
|
||||
<DockPanel>
|
||||
<StackPanel DockPanel.Dock="Top" Spacing="6" Margin="0,0,0,8">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8" IsEnabled="{Binding CanTransferSteps}">
|
||||
@ -122,23 +122,7 @@
|
||||
<Button DockPanel.Dock="Bottom" Content="加步骤" Margin="0,8,0,0" Padding="0,6" Command="{Binding Recipe.AddStepCommand}" />
|
||||
<ListBox ItemTemplate="{StaticResource StepRow}" ItemsSource="{Binding Recipe.Steps}" SelectedItem="{Binding Recipe.SelectedStep}" Classes="Pick" />
|
||||
</DockPanel>
|
||||
<StackPanel Grid.Column="2" Margin="12,0,0,0" Spacing="8">
|
||||
<TextBlock Text="标准视频" FontWeight="Bold" />
|
||||
<StackPanel DataContext="{Binding SopRecording}" Spacing="8">
|
||||
<Image Source="{Binding Playback.Frame}" Height="230" Stretch="Uniform" />
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Button Content="{Binding PlayVideoButtonText}" Command="{Binding PlayVideoCommand}" />
|
||||
<Button Content="停止" Command="{Binding StopVideoCommand}" />
|
||||
</StackPanel>
|
||||
<Slider Minimum="0" Maximum="100" Value="{Binding Playback.Progress, Mode=TwoWay}" IsEnabled="{Binding CanSeekVideo}" ToolTip.Tip="拖动跳转视频位置" />
|
||||
<TextBlock Text="{Binding Playback.TimeText}" />
|
||||
<TextBlock Text="{Binding Status}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
<Button Content="获取关键帧" Command="{Binding CaptureStepKeyFrameCommand}" ToolTip.Tip="将当前显示画面保存为选中步骤的关键帧" />
|
||||
<TextBlock Text="{Binding Recipe.SelectedStep.KeyFrameLabel}" TextWrapping="Wrap" />
|
||||
<TextBlock Text="{Binding StepKeyFrameStatus}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
<ScrollViewer Grid.Column="1" Margin="12,0,0,0" VerticalScrollBarVisibility="Auto" DataContext="{Binding Recipe.SelectedStep}">
|
||||
<ScrollViewer Grid.Row="1" Margin="0,12,0,0" VerticalScrollBarVisibility="Auto" DataContext="{Binding Recipe.SelectedStep}">
|
||||
<StackPanel>
|
||||
<Grid Classes="Row">
|
||||
<Grid.ColumnDefinitions>
|
||||
@ -300,6 +284,28 @@
|
||||
<ItemsControl ItemsSource="{Binding ViolationRules.Items}" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
<Grid Grid.Column="1" Margin="6,0,0,0" RowDefinitions="Auto,*,Auto,Auto">
|
||||
<TextBlock Text="标准视频" FontWeight="Bold" Margin="0,0,0,8" />
|
||||
<Border x:Name="StepVideoViewport" Grid.Row="1" Background="#080E14">
|
||||
<Image x:Name="StepVideoImage" Source="{Binding SopRecording.Playback.Frame}" Stretch="Uniform" />
|
||||
</Border>
|
||||
<StackPanel Grid.Row="2" DataContext="{Binding SopRecording}" Spacing="8" Margin="0,8,0,0">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Button Content="播放" Command="{Binding PlayVideoCommand}" />
|
||||
<Button Content="暂停" Command="{Binding PauseVideoCommand}" />
|
||||
<Button Content="停止" Command="{Binding StopVideoCommand}" />
|
||||
</StackPanel>
|
||||
<Slider Minimum="0" Maximum="100" Value="{Binding Playback.Progress, Mode=TwoWay}" IsEnabled="{Binding CanSeekVideo}" ToolTip.Tip="拖动跳转视频位置" />
|
||||
<TextBlock Text="{Binding Playback.TimeText}" />
|
||||
<TextBlock Text="{Binding Status}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="3" Spacing="8" Margin="0,8,0,0">
|
||||
<Button Content="获取关键帧" Command="{Binding CaptureStepKeyFrameCommand}" />
|
||||
<TextBlock Text="{Binding Recipe.SelectedStep.KeyFrameLabel}" TextWrapping="Wrap" />
|
||||
<TextBlock Text="{Binding StepKeyFrameStatus}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="区域">
|
||||
@ -471,7 +477,8 @@
|
||||
<Button Content="停止录像" Command="{Binding StopRecordingCommand}" />
|
||||
<Button Content="重新录制" Command="{Binding RestartCommand}" />
|
||||
<Button Content="导入视频" Command="{Binding ImportVideoCommand}" ToolTip.Tip="选择视频并复制到当前配方的 sop_stand/sop.avi,覆盖已有标准视频" />
|
||||
<Button Content="{Binding PlayVideoButtonText}" Command="{Binding PlayVideoCommand}" />
|
||||
<Button Content="播放" Command="{Binding PlayVideoCommand}" />
|
||||
<Button Content="暂停" Command="{Binding PauseVideoCommand}" />
|
||||
<Button Content="测试流程" Command="{Binding TestFlowCommand}" ToolTip.Tip="从头播放标准视频,使用当前编辑的步骤和区域进行流程检测" />
|
||||
<Button Content="停止播放" Command="{Binding StopVideoCommand}" />
|
||||
<Button Content="打开保存位置" Command="{Binding RevealCommand}" />
|
||||
|
||||
@ -137,8 +137,10 @@ internal static class Program
|
||||
var selected = vm.Recipe.SelectedStep!;
|
||||
vm.CaptureStepKeyFrameCommand.Execute();
|
||||
Check(selected.KeyFrameBase64.Length == 0, "Cannot capture a keyframe without a displayed video frame");
|
||||
Pump(model.Playback.PlayAsync(model.StandardVideoPath));
|
||||
model.Playback.Pause();
|
||||
model.PlayVideoCommand.Execute(); Until(() => !model.IsBusy && model.Playback.IsPlaying);
|
||||
Check(!model.PlayVideoCommand.CanExecute() && model.PauseVideoCommand.CanExecute(), "Separate play and pause commands expose the correct playing state");
|
||||
model.PauseVideoCommand.Execute(); Until(() => !model.IsBusy && !model.Playback.IsPlaying);
|
||||
Check(model.PlayVideoCommand.CanExecute() && !model.PauseVideoCommand.CanExecute(), "Pause only pauses; play becomes available to resume");
|
||||
Pump(model.Playback.SeekAsync(50));
|
||||
var displayed = Convert.ToBase64String(model.Playback.Frame!.ToPngBytes());
|
||||
vm.CaptureStepKeyFrameCommand.Execute();
|
||||
@ -162,6 +164,10 @@ internal static class Program
|
||||
model.FlowTestConfigProvider = () => config;
|
||||
var view = new RecipeEditor { DataContext = vm };
|
||||
var window = new Window { Content = view, Width = 1040, Height = 760 }; window.Show(); window.UpdateLayout();
|
||||
var stepVideo = view.FindControl<Border>("StepVideoViewport")!;
|
||||
Check(stepVideo.Bounds.Width >= window.Bounds.Width * .44 && stepVideo.Bounds.Width <= window.Bounds.Width * .53,
|
||||
"Step video occupies half the available editor width");
|
||||
|
||||
var tabs = view.GetVisualDescendants().OfType<TabControl>().Single();
|
||||
tabs.SelectedItem = tabs.Items.OfType<TabItem>().Single(t => t.Header?.ToString() == "SOP流程视频");
|
||||
window.UpdateLayout(); Dispatcher.UIThread.RunJobs();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user