Skip to content

Commit

Permalink
feat(UI): Added keyboardSeekDistance config to UI (shaka-project#4246)
Browse files Browse the repository at this point in the history
This new configuration value allows users to determine how far
the video seeks when you press the arrow keys on the video
element.

Closes shaka-project#4245

<!--
Please remember to:

1. Use Conventional Commits syntax (fix: ..., feat: ..., etc.) in commits and
   PR title (https://www.conventionalcommits.org/)
2. Tag any related or fixed issues ("Issue shaka-project#123", "Closes shaka-project#420")
3. Sign the Google CLA if you haven't (https://cla.developers.google.com)

You may delete this comment from the PR description.
-->
  • Loading branch information
theodab authored May 19, 2022
1 parent 84fe995 commit 6084ca6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
14 changes: 8 additions & 6 deletions ui/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,21 +1260,23 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
return;
}

const keyboardSeekDistance = this.config_.keyboardSeekDistance;

switch (event.key) {
case 'ArrowLeft':
// If it's not focused on the volume bar, move the seek time backward
// for 5 sec. Otherwise, the volume will be adjusted automatically.
if (this.seekBar_ && !isVolumeBar) {
// for a few sec. Otherwise, the volume will be adjusted automatically.
if (this.seekBar_ && !isVolumeBar && keyboardSeekDistance > 0) {
event.preventDefault();
this.seek_(this.seekBar_.getValue() - 5);
this.seek_(this.seekBar_.getValue() - keyboardSeekDistance);
}
break;
case 'ArrowRight':
// If it's not focused on the volume bar, move the seek time forward
// for 5 sec. Otherwise, the volume will be adjusted automatically.
if (this.seekBar_ && !isVolumeBar) {
// for a few sec. Otherwise, the volume will be adjusted automatically.
if (this.seekBar_ && !isVolumeBar && keyboardSeekDistance > 0) {
event.preventDefault();
this.seek_(this.seekBar_.getValue() + 5);
this.seek_(this.seekBar_.getValue() + keyboardSeekDistance);
}
break;
// Jump to the beginning of the video's seek range.
Expand Down
8 changes: 7 additions & 1 deletion ui/externs/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ shaka.extern.UIVolumeBarColors;
* enableKeyboardPlaybackControls: boolean,
* enableFullscreenOnRotation: boolean,
* forceLandscapeOnFullscreen: boolean,
* enableTooltips: boolean
* enableTooltips: boolean,
* keyboardSeekDistance: number
* }}
*
* @property {!Array.<string>} controlPanelElements
Expand Down Expand Up @@ -177,6 +178,11 @@ shaka.extern.UIVolumeBarColors;
* Whether or not buttons in the control panel display tooltips that contain
* information about their function.
* Defaults to false.
* @property {number} keyboardSeekDistance
* The time interval, in seconds, to seek when the user presses the left or
* right keyboard keys when the video is selected. If less than or equal to 0,
* no seeking will occur.
* Defaults to 5 seconds.
* @exportDoc
*/
shaka.extern.UIConfiguration;
Expand Down
1 change: 1 addition & 0 deletions ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ shaka.ui.Overlay = class {
enableFullscreenOnRotation: true,
forceLandscapeOnFullscreen: true,
enableTooltips: false,
keyboardSeekDistance: 5,
};

// Check AirPlay support
Expand Down

0 comments on commit 6084ca6

Please sign in to comment.