Skip to content

Add playback speed control and timeline seek hotkeys to VideoViewer - #2000

Open
v-shift-bit wants to merge 1 commit into
QL-Win:masterfrom
v-shift-bit:video-speed-and-seek-hotkeys
Open

v-shift-bit wants to merge 1 commit into
QL-Win:masterfrom
v-shift-bit:video-speed-and-seek-hotkeys

Conversation

@v-shift-bit

@v-shift-bit v-shift-bit commented Sep 14, 2026

Copy link
Copy Markdown

Summary

This PR adds two features to the QuickLook.Plugin.VideoViewer plugin:

  1. Playback speed control

    • New speed button in the control bar showing the current rate (e.g. 1x), styled to match the existing HardwareAccelerationButtonStyle.
    • Click to cycle through presets: 0.25x, 0.5x, 0.75x, 1x, 1.25x, 1.5x, 1.75x, 2x.
    • Keyboard shortcuts: + / - to step through presets, 0 to reset to 1x.
    • The chosen speed is persisted via SettingHelper and restored the next time a video is opened.
    • Implemented via MediaUriElement.SpeedRatio (already exposed by WPFMediaKit), no changes to native/DirectShow code required.
  2. Timeline seek hotkeys

    • Shift + Left/Right — seek 5 seconds backward/forward.
    • Ctrl + Left/Right — seek 30 seconds backward/forward.
    • Home / End — jump to the start/end of the video.
    • Seeking is clamped to [0, MediaDuration] and works with MediaPosition/MediaDuration (100ns ticks), consistent with the existing seeking API.

Why

QuickLook's video preview currently has no way to change playback speed or jump around the timeline without dragging the seek bar with the mouse — both are common expectations for a media preview tool.

Implementation notes

  • All changes are contained to QuickLook.Plugin.VideoViewer (ViewerPanel.xaml, ViewerPanel.xaml.cs, Styles.xaml, Translations.config).
  • PreviewKeyDown is used for the new hotkeys and does not interfere with QuickLook's existing global hotkey dispatcher (KeystrokeDispatcher), since it only handles keys not already used elsewhere in the viewer.
  • Added BTN_Speed translation strings for en and ru-RU; other locales fall back to English.

Testing

  • Built and tested locally on Windows (Release / Any CPU) with various video formats.
  • Verified speed changes and seeking work correctly and that the setting persists across sessions.

Summary by Sourcery

Add playback speed control and keyboard-based timeline navigation to the video viewer.

New Features:

  • Add playback speed controls with preset cycling, keyboard shortcuts, and persisted user preferences.
  • Add keyboard shortcuts for short and long timeline seeks and jumping to the beginning or end of a video.

Enhancements:

  • Update the video viewer controls and styling with a localized playback speed button and tooltip.

@sourcery-ai

sourcery-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Reviewer's Guide

The VideoViewer gains a persisted playback-speed selector and keyboard timeline navigation, implemented entirely in the WPF viewer by applying MediaUriElement.SpeedRatio, manipulating MediaPosition in 100ns ticks, and capturing the new shortcuts through the focused panel.

Sequence diagram for VideoViewer speed control and timeline hotkeys

sequenceDiagram
    participant User
    participant ViewerPanel
    participant SettingHelper
    participant MediaUriElement

    User->>ViewerPanel: PreviewKeyDown
    alt Shift+Left/Right or Ctrl+Left/Right
        ViewerPanel->>MediaUriElement: Seek(deltaTicks)
        ViewerPanel->>MediaUriElement: SeekTo(clampedPosition)
        ViewerPanel->>MediaUriElement: set MediaPosition
    else Home or End
        ViewerPanel->>MediaUriElement: SeekTo(0 or MediaDuration)
        ViewerPanel->>MediaUriElement: set MediaPosition
    else +/- or 0
        ViewerPanel->>ViewerPanel: CycleSpeed(direction)
        ViewerPanel->>MediaUriElement: set SpeedRatio
    end

    User->>ViewerPanel: LoadAndPlay(path)
    ViewerPanel->>SettingHelper: Get PlaybackSpeed
    SettingHelper-->>ViewerPanel: persisted speed
    ViewerPanel->>MediaUriElement: set SpeedRatio
    ViewerPanel->>MediaUriElement: Play()

    User->>ViewerPanel: Dispose()
    ViewerPanel->>SettingHelper: Set PlaybackSpeed
Loading

File-Level Changes

Change Details Files
Adds persisted playback-speed control with UI and keyboard cycling.
  • Defines eight speed presets and binds the selected value to MediaUriElement.SpeedRatio.
  • Adds a styled speed button, tooltip, click cycling, right-click reset, and +/-/0 hotkeys.
  • Loads and saves the speed through SettingHelper and updates the displayed rate via property notification.
QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml
QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs
QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Styles.xaml
QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Translations.config
Adds keyboard-based timeline seeking with duration-bound positions.
  • Handles Shift/Ctrl plus Left/Right for 5- and 30-second relative seeks.
  • Handles Home and End for absolute start/end seeks using MediaPosition and MediaDuration ticks.
  • Clamps seek targets to valid media bounds and routes handled shortcuts through a focused viewer panel.
QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs" line_range="319" />
<code_context>
+                break;
+
+            case Key.OemPlus or Key.Add when modifiers == ModifierKeys.None:
+                CycleSpeed(1);
+                e.Handled = true;
+                break;
+
+            case Key.OemMinus or Key.Subtract when modifiers == ModifierKeys.None:
</code_context>
<issue_to_address>
**issue (bug_risk):** The `+` playback-speed shortcut does not work on a standard keyboard because `+` is produced as `Shift+OemPlus`, while this branch only matches `OemPlus` when `ModifierKeys.None` is active.

**Triggers:** When the user presses the standard keyboard `+` key rather than NumPad `Add`.

**Suggested fix:** Accept `ModifierKeys.Shift` for `Key.OemPlus` (while retaining the unmodified `Key.Add` case for the numeric keypad).

```suggestion
            case Key.OemPlus when modifiers == ModifierKeys.Shift:
            case Key.Add when modifiers == ModifierKeys.None:
```
</issue_to_address>

### Comment 2
<location path="QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs" line_range="315-316" />
<code_context>
+                break;
+
+            case Key.End when modifiers == ModifierKeys.None:
+                SeekTo(mediaElement.MediaDuration);
+                e.Handled = true;
+                break;
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Seeking to exactly `MediaDuration` triggers the existing `MediaEnded` handler, which immediately resets `MediaPosition` to `0L`; consequently, the `End` hotkey does not leave playback at the end of the video.

**Triggers:** When `End` is pressed on a loaded video and the media backend raises `MediaEnded` after positioning at its duration.

**Suggested fix:** Seek to the last valid position before the duration, or suppress the end-reset behavior for an explicit end seek.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs:319, QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs:316


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

e.Handled = true;
break;

case Key.OemPlus or Key.Add when modifiers == ModifierKeys.None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The + playback-speed shortcut does not work on a standard keyboard because + is produced as Shift+OemPlus, while this branch only matches OemPlus when ModifierKeys.None is active.

Triggers: When the user presses the standard keyboard + key rather than NumPad Add.

Suggested fix: Accept ModifierKeys.Shift for Key.OemPlus (while retaining the unmodified Key.Add case for the numeric keypad).

Suggested change
case Key.OemPlus or Key.Add when modifiers == ModifierKeys.None:
case Key.OemPlus when modifiers == ModifierKeys.Shift:
case Key.Add when modifiers == ModifierKeys.None:

Comment on lines +315 to +316
SeekTo(mediaElement.MediaDuration);
e.Handled = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Seeking to exactly MediaDuration triggers the existing MediaEnded handler, which immediately resets MediaPosition to 0L; consequently, the End hotkey does not leave playback at the end of the video.

Triggers: When End is pressed on a loaded video and the media backend raises MediaEnded after positioning at its duration.

Suggested fix: Seek to the last valid position before the duration, or suppress the end-reset behavior for an explicit end seek.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant