From b1c26c5b167a69f5707e98716b2c1dac8970c629 Mon Sep 17 00:00:00 2001 From: Rahim Alwer Date: Wed, 18 Oct 2023 23:06:21 +1100 Subject: [PATCH] feat(player): new speed up and slow down keyboard shortcuts --- packages/vidstack/src/core/keyboard/controller.ts | 10 ++++++++++ packages/vidstack/src/core/keyboard/types.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/packages/vidstack/src/core/keyboard/controller.ts b/packages/vidstack/src/core/keyboard/controller.ts index 2f5a93959..686a4c753 100644 --- a/packages/vidstack/src/core/keyboard/controller.ts +++ b/packages/vidstack/src/core/keyboard/controller.ts @@ -16,6 +16,8 @@ export const MEDIA_KEY_SHORTCUTS: MediaKeyShortcuts = { seekForward: 'l L ArrowRight', volumeUp: 'ArrowUp', volumeDown: 'ArrowDown', + speedUp: '>', + slowDown: '<', }; const MODIFIER_KEYS = new Set(['Shift', 'Alt', 'Meta', 'Control']), @@ -154,6 +156,14 @@ export class MediaKeyboardController extends MediaPlayerController { case 'toggleFullscreen': this._media.remote.toggleFullscreen('prefer-media', event); break; + case 'speedUp': + case 'slowDown': + const playbackRate = this.$state.playbackRate(); + this._media.remote.changePlaybackRate( + Math.max(0.25, Math.min(2, playbackRate + (method === 'speedUp' ? 0.25 : -0.25))), + event, + ); + break; default: this._media.remote[method]?.(event); } diff --git a/packages/vidstack/src/core/keyboard/types.ts b/packages/vidstack/src/core/keyboard/types.ts index 996c894f0..93d2d00a3 100644 --- a/packages/vidstack/src/core/keyboard/types.ts +++ b/packages/vidstack/src/core/keyboard/types.ts @@ -8,6 +8,8 @@ export interface MediaKeyShortcuts { toggleCaptions?: string | null; seekBackward?: string | null; seekForward?: string | null; + speedUp?: string | null; + slowDown?: string | null; volumeUp?: string | null; volumeDown?: string | null; }