/// <summary> /// On key down /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.F) { _applicationService.IsFullScreen = !_applicationService.IsFullScreen; } if (e.Key == Key.Space) { if (Media.IsPlaying) { await PauseMedia(); } else { await PlayMedia(); } } if (!(DataContext is MediaPlayerViewModel vm) || !vm.SubtitleItems.Any()) { return; } switch (e.Key) { case Key.H: if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) { SubtitleDelay += 1000; } else { SubtitleDelay += 1000; } break; case Key.G: if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) { SubtitleDelay -= 1000; } else { SubtitleDelay -= 1000; } break; default: return; } Delay.Text = $"Subtitle delay: {SubtitleDelay} ms"; if (SubtitleDelaySemaphore.CurrentCount == 0) { return; } await SubtitleDelaySemaphore.WaitAsync(); var increasedPanelOpacityAnimation = new DoubleAnimationUsingKeyFrames { Duration = new Duration(TimeSpan.FromSeconds(0.1)), KeyFrames = new DoubleKeyFrameCollection { new EasingDoubleKeyFrame(0.6, KeyTime.FromPercent(1.0), new PowerEase { EasingMode = EasingMode.EaseInOut }) } }; var increasedSubtitleDelayOpacityAnimation = new DoubleAnimationUsingKeyFrames { Duration = new Duration(TimeSpan.FromSeconds(0.1)), KeyFrames = new DoubleKeyFrameCollection { new EasingDoubleKeyFrame(1.0, KeyTime.FromPercent(1.0), new PowerEase { EasingMode = EasingMode.EaseInOut }) } }; SubtitleDelayPanel.BeginAnimation(OpacityProperty, increasedPanelOpacityAnimation); Delay.BeginAnimation(OpacityProperty, increasedSubtitleDelayOpacityAnimation); await Task.Delay(2000); var decreasedOpacityAnimation = new DoubleAnimationUsingKeyFrames { Duration = new Duration(TimeSpan.FromSeconds(0.1)), KeyFrames = new DoubleKeyFrameCollection { new EasingDoubleKeyFrame(0.0, KeyTime.FromPercent(1.0), new PowerEase { EasingMode = EasingMode.EaseInOut }) } }; SubtitleDelayPanel.BeginAnimation(OpacityProperty, decreasedOpacityAnimation); Delay.BeginAnimation(OpacityProperty, decreasedOpacityAnimation); SubtitleDelaySemaphore.Release(); }