example.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Video.js Hotkeys</title>
  6. <link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet">
  7. <script src="https://vjs.zencdn.net/7.4.1/video.js"></script>
  8. <style>
  9. .video-js .vjs-menu-button-inline {
  10. width: 12em;
  11. }
  12. .vjs-menu-button-inline .vjs-menu {
  13. display: block;
  14. opacity: 1;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div>
  20. You can see the Video.js Hotkeys plugin in use below.
  21. Look at the source to see how to use it with your own videos.
  22. </div>
  23. <video id="video1" class="video-js vjs-default-skin vjs-big-play-centered" height="300" width="600" controls data-setup="{}">
  24. <source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
  25. <source src="http://vjs.zencdn.net/v/oceans.webm" type='video/webm'>
  26. <source src="http://vjs.zencdn.net/v/oceans.ogv" type='video/ogg'>
  27. <p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that
  28. <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>
  29. </video>
  30. <script src="videojs.hotkeys.js"></script>
  31. <script>
  32. // initialize the plugin
  33. videojs('video1').ready(function() {
  34. this.hotkeys({
  35. volumeStep: 0.1,
  36. seekStep: 5,
  37. enableMute: true,
  38. enableFullscreen: true,
  39. enableNumbers: false,
  40. enableVolumeScroll: true,
  41. enableHoverScroll: true,
  42. // Mimic VLC seek behavior, and default to 5.
  43. seekStep: function(e) {
  44. if (e.ctrlKey && e.altKey) {
  45. return 5*60;
  46. } else if (e.ctrlKey) {
  47. return 60;
  48. } else if (e.altKey) {
  49. return 10;
  50. } else {
  51. return 5;
  52. }
  53. },
  54. // Enhance existing simple hotkey with a complex hotkey
  55. fullscreenKey: function(e) {
  56. // fullscreen with the F key or Ctrl+Enter
  57. return ((e.which === 70) || (e.ctrlKey && e.which === 13));
  58. },
  59. // Custom Keys
  60. customKeys: {
  61. // Add new simple hotkey
  62. simpleKey: {
  63. key: function(e) {
  64. // Toggle something with S Key
  65. return (e.which === 83);
  66. },
  67. handler: function(player, options, e) {
  68. // Example
  69. if (player.paused()) {
  70. player.play();
  71. } else {
  72. player.pause();
  73. }
  74. }
  75. },
  76. // Add new complex hotkey
  77. complexKey: {
  78. key: function(e) {
  79. // Toggle something with CTRL + D Key
  80. return (e.ctrlKey && e.which === 68);
  81. },
  82. handler: function(player, options, event) {
  83. // Example
  84. if (options.enableMute) {
  85. player.muted(!player.muted());
  86. }
  87. }
  88. },
  89. // Override number keys example from https://github.com/ctd1500/videojs-hotkeys/pull/36
  90. numbersKey: {
  91. key: function(event) {
  92. // Override number keys
  93. return ((event.which > 47 && event.which < 59) || (event.which > 95 && event.which < 106));
  94. },
  95. handler: function(player, options, event) {
  96. // Do not handle if enableModifiersForNumbers set to false and keys are Ctrl, Cmd or Alt
  97. if (options.enableModifiersForNumbers || !(event.metaKey || event.ctrlKey || event.altKey)) {
  98. var sub = 48;
  99. if (event.which > 95) {
  100. sub = 96;
  101. }
  102. var number = event.which - sub;
  103. player.currentTime(player.duration() * number * 0.1);
  104. }
  105. }
  106. },
  107. emptyHotkey: {
  108. // Empty
  109. },
  110. withoutKey: {
  111. handler: function(player, options, event) {
  112. console.log('withoutKey handler');
  113. }
  114. },
  115. withoutHandler: {
  116. key: function(e) {
  117. return true;
  118. }
  119. },
  120. malformedKey: {
  121. key: function() {
  122. console.log('I have a malformed customKey. The Key function must return a boolean.');
  123. },
  124. handler: function(player, options, event) {
  125. //Empty
  126. }
  127. }
  128. }
  129. });
  130. });
  131. </script>
  132. </body>
  133. </html>