Skip to content

Commit

Permalink
feat(player): new speed up and slow down keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Oct 18, 2023
1 parent d87cb18 commit b1c26c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/vidstack/src/core/keyboard/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/vidstack/src/core/keyboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b1c26c5

Please sign in to comment.