Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add enableSeekPause option #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ The **Enter**/**Return** key may be used instead to activate the control element
`seekStep` will also need to be changed to get a proper broadcast-style jog.
This feature and the changes for seekStep are explained a bit more in [PR #12](https://github.com/ctd1500/videojs-hotkeys/pull/12) (default `false`)
(**Note:** This isn't a feature for everyone, and enabling JogStyle will disable the volume hotkeys)
- `enableSeekPause` (boolean): Right/Left Arrow keys will trigger pause/playing events for consistency with video.js seekbar [PR #41](https://github.com/ctd1500/videojs-hotkeys/pull/41). You can disable it for more smooth seek (default `true`)

**There are more options specifically for customizing hotkeys described below.**

Expand Down
1 change: 1 addition & 0 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
enableNumbers: false,
enableVolumeScroll: true,
enableHoverScroll: true,
enableSeekPause: false,
captureDocumentHotkeys: true,
documentHotkeysFocusElementFilter: e => e.tagName.toLowerCase() === "body",

Expand Down
22 changes: 12 additions & 10 deletions videojs.hotkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
documentHotkeysFocusElementFilter: function () { return false },
enableModifiersForNumbers: true,
enableInactiveFocus: true,
enableSeekPause: true,
skipInitialFocus: false,
playPauseKey: playPauseKey,
rewindKey: rewindKey,
Expand Down Expand Up @@ -77,6 +78,7 @@
documentHotkeysFocusElementFilter = options.documentHotkeysFocusElementFilter,
enableModifiersForNumbers = options.enableModifiersForNumbers,
enableInactiveFocus = options.enableInactiveFocus,
enableSeekPause = options.enableSeekPause,
skipInitialFocus = options.skipInitialFocus;

var videojsVer = videojs.VERSION;
Expand Down Expand Up @@ -162,10 +164,10 @@

// Seeking with the left/right arrow keys
case cRewind: // Seek Backward
wasPlaying = !player.paused();
ePreventDefault();
if (wasPlaying) {
player.pause();
if (enableSeekPause) {
wasPlaying = !player.paused();
if (wasPlaying) player.pause();
}
seekTime = player.currentTime() - seekStepD(event);
// The flash player tech will allow you to seek into negative
Expand All @@ -174,15 +176,15 @@
seekTime = 0;
}
player.currentTime(seekTime);
if (wasPlaying) {
silencePromise(player.play());
if (enableSeekPause) {
if (wasPlaying) silencePromise(player.play());
}
break;
case cForward: // Seek Forward
wasPlaying = !player.paused();
ePreventDefault();
if (wasPlaying) {
player.pause();
if (enableSeekPause) {
wasPlaying = !player.paused();
if (wasPlaying) player.pause();
}
seekTime = player.currentTime() + seekStepD(event);
// Fixes the player not sending the end event if you
Expand All @@ -191,8 +193,8 @@
seekTime = wasPlaying ? duration - .001 : duration;
}
player.currentTime(seekTime);
if (wasPlaying) {
silencePromise(player.play());
if (enableSeekPause) {
if (wasPlaying) silencePromise(player.play());
}
break;

Expand Down