Giter VIP home page Giter VIP logo

Comments (9)

ctd1500 avatar ctd1500 commented on June 10, 2024

I took a look, but it seemed to require editing the plugin itself in order to specify any sort of customized keys.

Perhaps you need other custom keys that I haven't built yet, but maybe this format can work better?
https://github.com/ctd1500/videojs-hotkeys/blob/modular/videojs.hotkeys.js

This would allow for easily replacing hotkeys with your own with an option parameter, without requiring editing the plugin script.
For example, replacing / changing the fullscreen hotkey:

this.hotkeys({
  volumeStep: 0.2,
  enableFullscreen: true,
  fullscreenKey: function(e) {
    // fullscreen with the F key or Ctrl+Enter
    return ((e.which === 70) || (e.ctrlKey && e.which === 13));
  }
});

from videojs-hotkeys.

aitoraznar avatar aitoraznar commented on June 10, 2024

Ok, I give it a try.

In my case I need to provide hotkeys to:

Add new simple hotkey

  • Toggle subtitules with S Key

Enhance existing simple hotkey with a complex hotkey

  • Toggle FullScreen with CTRL + ENTER

Add new complex hotkey

  • Toggle "awesome behaviour " with CTRL + D

I will rewrite my code following your way.

from videojs-hotkeys.

ctd1500 avatar ctd1500 commented on June 10, 2024

I can change this a little bit, to enable such functionality.

from videojs-hotkeys.

ctd1500 avatar ctd1500 commented on June 10, 2024

I've just updated the branch.
https://github.com/ctd1500/videojs-hotkeys/blob/modular/videojs.hotkeys.js

Something simple like this could be done.

this.hotkeys({
  playPauseKey: function(e, player) {
    // spacebar toggle Play/Pause
    if (e.which === 32) {
      return true;
    }

    // catch "S" key for subtitles
    if (e.which === 83) {
      // Toggle subtitles with code here, or call another function you wrote
      // Pass the "player" variable which is the current video.js player object.
      toggleSubtitles(player);
      // return false so that we don't play/pause when toggling subtitles.
      return false;
    }
    return false;
  }
});

Or I could also add a new customKey: function(e, player) { } function to add any new keys without needing to override existing keys.
Something like:

this.hotkeys({
  customKey: function(e, player) {
    // catch "S" key for subtitles
    if (e.which === 83) {
      // Toggle subtitles with code here, or call another function you wrote
      // Pass the "player" variable which is the current video.js player object.
      toggleSubtitles(player);
    }
    // Wouldn't need to return anything, since the customKey function would 
    // not do anything by itself.
    return;
  }
});

from videojs-hotkeys.

aitoraznar avatar aitoraznar commented on June 10, 2024

Hi,

Checkout my branch:
https://github.com/ReNDeZOwnler/videojs-hotkeys/tree/modular

  • videojs.hotkeys.js
  • example.html

from videojs-hotkeys.

ctd1500 avatar ctd1500 commented on June 10, 2024

I just gave it a test run, it seems pretty good to me.
Want to create a pull request? Then I can start putting it into the next release.

from videojs-hotkeys.

aitoraznar avatar aitoraznar commented on June 10, 2024

Ok, I have some other suggestions.

I'll create a pull request for this a threat the other things in other issues.

from videojs-hotkeys.

aitoraznar avatar aitoraznar commented on June 10, 2024

You can close this issue when you merge the pull request.

from videojs-hotkeys.

ctd1500 avatar ctd1500 commented on June 10, 2024

Thanks.

from videojs-hotkeys.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.