Skip to content

Commit

Permalink
feat: add enableSeekPause option
Browse files Browse the repository at this point in the history
  • Loading branch information
EastSun5566 committed Dec 1, 2022
1 parent 8725196 commit 63ef759
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 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 @@ -163,23 +165,37 @@
// Seeking with the left/right arrow keys
case cRewind: // Seek Backward
ePreventDefault();
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
// numbers and break the seekbar, so try to prevent that.
if (seekTime <= 0) {
seekTime = 0;
}
player.currentTime(seekTime);
if (enableSeekPause) {
if (wasPlaying) silencePromise(player.play());
}
break;
case cForward: // Seek Forward
ePreventDefault();
if (enableSeekPause) {
wasPlaying = !player.paused();
if (wasPlaying) player.pause();
}
seekTime = player.currentTime() + seekStepD(event);
// Fixes the player not sending the end event if you
// try to seek past the duration on the seekbar.
if (seekTime >= duration) {
seekTime = wasPlaying ? duration - .001 : duration;
}
player.currentTime(seekTime);
if (enableSeekPause) {
if (wasPlaying) silencePromise(player.play());
}
break;

// Volume control with the up/down arrow keys
Expand Down

0 comments on commit 63ef759

Please sign in to comment.