npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@youon/videojs-hotkeys

v0.2.26

Published

Adds more hotkey support to video.js

Downloads

53

Readme

videojs-hotkeys



Introduction

A plugin for Video.js that enables keyboard hotkeys when the player has focus.

  • Space bar toggles play/pause.
  • Right and Left Arrow keys seek the video forwards and back.
  • Up and Down Arrow keys increase and decrease the volume.
  • M key toggles mute/unmute.
  • F key toggles fullscreen off and on. (Does not work in Internet Explorer, it seems to be a limitation where scripts cannot request fullscreen without a mouse click)
  • Double-clicking with the mouse toggles fullscreen off and on.
  • Number keys from 0-9 skip to a percentage of the video. 0 is 0% and 9 is 90%.

Note: clicking any of the control buttons such as Play/Pause, Fullscreen, or Mute, will remove focus on the player which appears to "break" the hotkeys. This is for accessibility reasons so that people who do not use or know about the hotkeys can still properly use the Tab key to highlight the control buttons and press space to toggle them.

To restore focus, just click on the video, or an empty part of the control bar at the bottom of the video player.

To override this behaviour, set the flag alwaysCaptureHotkeys to true. This will "fix" hotkeys. For accessibility, the Tab key may be used in combination with the Enter/Return key to navigate and activate control buttons.

Empty control bar space

Usage

Include the plugin:

CDN version

You can either load the current release:

<script src="//cdn.sc.gl/videojs-hotkeys/0.2/videojs.hotkeys.min.js"></script>

Or always load the latest version:

<script src="//cdn.sc.gl/videojs-hotkeys/latest/videojs.hotkeys.min.js"></script>

Self hosted

<script src="/path/to/videojs.hotkeys.js"></script>

Enable the plugin

Add hotkeys to your Videojs ready function. Check the Options section below for the available options and their meaning.

videojs('vidId').ready(function() {
  this.hotkeys({
    volumeStep: 0.1,
    seekStep: 5,
    enableModifiersForNumbers: false
  });
});

Options

  • volumeStep (decimal): The percentage to increase/decrease the volume level when using the Up and Down Arrow keys (default: 0.1)
  • seekStep (integer or function): The number of seconds to seek forward and backwards when using the Right and Left Arrow keys, or a function that generates an integer given the KeyboardEvent (default: 5)
  • enableMute (boolean): Enables the volume mute to be toggle by pressing the M key (default: true)
  • enableVolumeScroll (boolean): Enables increasing/decreasing the volume by scrolling the mouse wheel (default: true)
  • enableHoverScroll (boolean): Only changes volume when the mouse is hovering over the volume control elements. This works in connection with enableVolumeScroll (default: false)
  • enableFullscreen (boolean): Enables toggling the video fullscreen by pressing the F key (default: true)
  • enableNumbers (boolean): Enables seeking the video by pressing the number keys (default true)
  • enableModifiersForNumbers (boolean): Enables the use of Ctrl/Alt/Cmd + Number keys for skipping around in the video, instead of switching browser tabs. This is enabled by default due to backwards compatibility PR #35 (default: true)
  • alwaysCaptureHotkeys (boolean): Forces the capture of hotkeys, even when control elements are focused. The Enter/Return key may be used instead to activate the control elements. (default: false) (Note: This feature may break accessibility, and cause unexpected behavior)
  • enableInactiveFocus (boolean): This reassigns focus to the player when the control bar fades out after a user has clicked a button on the control bar (default: true)
  • skipInitialFocus (boolean): This stops focusing the player on initial Play under unique autoplay situations. More information in Issue #44 (default: false)
  • enableJogStyle (boolean): Enables seeking the video in a broadcast-style jog by pressing the Up and Down Arrow keys. 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 (default false) (Note: This isn't a feature for everyone, and enabling JogStyle will disable the volume hotkeys)

There are more options specifically for customizing hotkeys described below.

Custom Hotkeys and Overrides

There are 2 methods available here. Simply overriding existing hotkeys, and creating new custom hotkeys.

Override existing hotkeys

Override functions are available for changing which, or adding additional, keys that are used as hotkeys to trigger an action.

Any override functions that you build must return a boolean. true if the matching key(s) were pressed, or false if they were not.

  • playPauseKey (function): This function can be used to override the Play/Pause toggle hotkey (Default key: Space)
  • rewindKey (function): This function can override the key for seeking backward/left in the video (Default key: Left Arrow)
  • forwardKey (function): This function can override the key for seeking forward/right in the video (Default key: Right Arrow)
  • volumeUpKey (function): This function can override the key for increasing the volume (Default key: Up Arrow)
  • volumeDownKey (function): This function can override the key for decreasing the volume (Default key: Down Arrow)
  • muteKey (function): This function can override the key for the volume muting toggle (Default key: M)
  • fullscreenKey (function): This function can override the key for the fullscreen toggle (Default key: F)

These allow you to change keys such as, instead of, or in addition to, "F" for Fullscreen, you can make Ctrl+Enter trigger fullscreen as well. Example usage:

videojs('vidId').ready(function() {
  this.hotkeys({
    volumeStep: 0.1,
    fullscreenKey: function(event, player) {
      // override fullscreen to trigger when pressing the F key or Ctrl+Enter
      return ((event.which === 70) || (event.ctrlKey && event.which === 13));
    }
  });
});

Create new custom hotkeys

  • customKeys (object): Create an object containing 1 or more sub-objects. Each sub-object must contain a key function and handler function
    • key (function): This function checks if the chosen keys were pressed. It must return a boolean, true if the keys match.
    • handler (function): This function runs your custom code if the result of the key function was true.
videojs('vidId').ready(function() {
  this.hotkeys({
    volumeStep: 0.1,
    customKeys: {
      // Create custom hotkeys
      ctrldKey: {
        key: function(event) {
          // Toggle something with CTRL + D Key
          return (event.ctrlKey && event.which === 68);
        },
        handler: function(player, options, event) {
          // Using mute as an example
          if (options.enableMute) {
            player.muted(!player.muted());
          }
        }
      }
    }
  });
});