1 | # Silvermine VideoJS Quality/Resolution Selector
|
2 |
|
3 | [](https://travis-ci.org/silvermine/videojs-quality-selector)
|
4 | [](https://coveralls.io/github/silvermine/videojs-quality-selector?branch=master)
|
5 | [](https://david-dm.org/silvermine/videojs-quality-selector)
|
6 | [](https://david-dm.org/silvermine/videojs-quality-selector?type=dev)
|
7 |
|
8 |
|
9 | ## What is it?
|
10 |
|
11 | A plugin for [videojs](http://videojs.com/) versions 6+ that adds a button to the control
|
12 | bar which will allow the user to choose from available video qualities or resolutions.
|
13 |
|
14 |
|
15 | ## How do I use it?
|
16 |
|
17 | There are three primary steps to use this plug-in: [(1) including](#includingrequiring),
|
18 | [(2) providing sources](#providing-video-sources), and [(3) adding the component the to
|
19 | `controlBar`](#adding-to-the-player). Please see the following for information on each
|
20 | step.
|
21 |
|
22 | ### Including/Requiring
|
23 |
|
24 | #### Using `<script>` tag
|
25 |
|
26 | The minified JS file can come from a downloaded copy or a CDN. When including
|
27 | it, make sure that the `<script>` tag for the plugin appears _after_ the
|
28 | include for [video.js](http://videojs.com/) (note that this plugin will look
|
29 | for `videojs` at `window.videojs`).
|
30 |
|
31 | There is an example of this in
|
32 | [`docs/demo/index.html`](./docs/demo/index.html).
|
33 |
|
34 | ##### From local file:
|
35 |
|
36 | ```js
|
37 | <script src="./path/to/video.min.js"></script>
|
38 | <script src="./path/to/silvermine-videojs-quality-selector.min.js"></script>
|
39 | ```
|
40 |
|
41 | ##### From [`unpkg`](https://unpkg.com/@silvermine/videojs-quality-selector/):
|
42 |
|
43 | ```js
|
44 | <link href="https://unpkg.com/@silvermine/videojs-quality-selector/dist/css/quality-selector.css" rel="stylesheet">
|
45 | <script src="./path/to/video.min.js"></script>
|
46 | <script src="https://unpkg.com/@silvermine/videojs-quality-selector/dist/js/silvermine-videojs-quality-selector.min.js"></script>
|
47 | ```
|
48 |
|
49 | #### Using `require`
|
50 |
|
51 | When using NPM/Browserify, first install the plugin.
|
52 |
|
53 | ```
|
54 | npm install --save @silvermine/videojs-quality-selector
|
55 | ```
|
56 |
|
57 | For `videojs` to use the plug-in, the plugin needs to register itself with the instance of
|
58 | `videojs`. This can be accomplished by:
|
59 |
|
60 | ```js
|
61 | var videojs = require('videojs');
|
62 |
|
63 | // The following registers the plugin with `videojs`
|
64 | require('@silvermine/videojs-quality-selector')(videojs);
|
65 | ```
|
66 |
|
67 | Remember to also add the CSS to your build. With most bundlers you can:
|
68 |
|
69 | ```js
|
70 | require('@silvermine/videojs-quality-selector/dist/css/quality-selector.css')
|
71 | ```
|
72 |
|
73 | ### Providing video sources
|
74 |
|
75 | Sources can be provided with either the `<source>` tag or via the `src` function on the
|
76 | instance of a `video.js` player.
|
77 |
|
78 | #### Using `<source>`
|
79 |
|
80 | ```html
|
81 | <video id="video_1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="268" data-setup='{}'>
|
82 | <source src="https://example.com/video_720.mp4" type="video/mp4" label="720P">
|
83 | <source src="https://example.com/video_480.mp4" type="video/mp4" label="480P" selected="true">
|
84 | <source src="https://example.com/video_360.mp4" type="video/mp4" label="360P">
|
85 | </video>
|
86 | ```
|
87 |
|
88 | #### Using `player.src()`
|
89 |
|
90 | ```js
|
91 | player.src([
|
92 | {
|
93 | src: 'https://example.com/video_720.mp4',
|
94 | type: 'video/mp4',
|
95 | label: '720P',
|
96 | },
|
97 | {
|
98 | src: 'https://example.com/video_480.mp4',
|
99 | type: 'video/mp4',
|
100 | label: '480P',
|
101 | selected: true,
|
102 | },
|
103 | {
|
104 | src: 'https://example.com/video_360.mp4',
|
105 | type: 'video/mp4',
|
106 | label: '360P',
|
107 | },
|
108 | ]);
|
109 | ```
|
110 |
|
111 | ### Adding to the player
|
112 |
|
113 | There are at least two ways to add the quality selector control to the player's control
|
114 | bar. The first is directly adding it via `addChild`. For example:
|
115 |
|
116 | ```
|
117 | player.controlBar.addChild('QualitySelector');
|
118 | ```
|
119 |
|
120 | The second option is to add the control via the player's options, for instance:
|
121 |
|
122 | ```
|
123 | var options, player;
|
124 |
|
125 | options = {
|
126 | controlBar: {
|
127 | children: [
|
128 | 'playToggle',
|
129 | 'progressControl',
|
130 | 'volumePanel',
|
131 | 'qualitySelector',
|
132 | 'fullscreenToggle',
|
133 | ],
|
134 | },
|
135 | };
|
136 |
|
137 | player = videojs('video_1', options);
|
138 | ```
|
139 |
|
140 | ## How do I contribute?
|
141 |
|
142 | We genuinely appreciate external contributions. See [our extensive
|
143 | documentation](https://github.com/silvermine/silvermine-info#contributing) on how to
|
144 | contribute.
|
145 |
|
146 |
|
147 | ## License
|
148 |
|
149 | This software is released under the MIT license. See [the license file](LICENSE) for more
|
150 | details.
|