在videojs中,如何取消绑定由videojs设置的键盘快捷键

In videojs, how to unbind keyboard shortcuts set by videojs?

本文关键字:videojs 绑定 设置 键盘 快捷键 何取消 取消      更新时间:2023-09-26

我正在通过修改源代码构建自己的基于videojs的媒体播放器。我现在想做的是绑定我自己的键盘快捷键,但显然videojs已经提前设置了一些快捷键。为了绑定我自己的键盘快捷键,我需要删除videojs中设置的默认快捷键。

如何解除绑定/删除由videojs设置的键盘快捷键?

在代码中我发现:

  ClickableComponent.prototype.handleKeyPress = function handleKeyPress(event) {
    // Support Space (32) or Enter (13) key operation to fire a click event
    if (event.which === 32 || event.which === 13) {
      event.preventDefault();
      this.handleClick(event);
    } else if (_Component.prototype.handleKeyPress) {
      _Component.prototype.handleKeyPress.call(this, event); // Pass keypress handling up for unsupported keys
    }
  };

我只是寻找32女巫是从空间的关键代码。玩家只使用两个快捷键来输入和空格。所以我推荐了这样的行:

  ClickableComponent.prototype.handleKeyPress = function handleKeyPress(event) {
    // Support Space (32) or Enter (13) key operation to fire a click event
    if (event.which === 32 || event.which === 13) {
      //event.preventDefault();
      //this.handleClick(event);
    } else if (_Component.prototype.handleKeyPress) {
      //_Component.prototype.handleKeyPress.call(this, event); // Pass keypress handling up for unsupported keys
    }
  };

唯一的问题是当你点击全屏图标并按空格键时,它将退出全屏模式。但其余部分被移除了。比如播放/暂停、静音和字幕。希望能有所帮助!对不起,我的英语不好。

编辑:在导入video.js后,我用下面的代码解决了这个问题:

$('.vjs-fullscreen-control').click(function(){
    setTimeout(function(){
       document.getElementById('example_video1').focus();
    },20);
});