Blame view

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