UNPKG

4.59 kBMarkdownView Raw
1# Silvermine VideoJS Quality/Resolution Selector
2
3[![Build Status](https://travis-ci.org/silvermine/videojs-quality-selector.svg?branch=master)](https://travis-ci.org/silvermine/videojs-quality-selector)
4[![Coverage Status](https://coveralls.io/repos/github/silvermine/videojs-quality-selector/badge.svg?branch=master)](https://coveralls.io/github/silvermine/videojs-quality-selector?branch=master)
5[![Dependency Status](https://david-dm.org/silvermine/videojs-quality-selector.svg)](https://david-dm.org/silvermine/videojs-quality-selector)
6[![Dev Dependency Status](https://david-dm.org/silvermine/videojs-quality-selector/dev-status.svg)](https://david-dm.org/silvermine/videojs-quality-selector?type=dev)
7
8
9## What is it?
10
11A plugin for [videojs](http://videojs.com/) versions 6+ that adds a button to the control
12bar which will allow the user to choose from available video qualities or resolutions.
13
14
15## How do I use it?
16
17There 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
20step.
21
22### Including/Requiring
23
24#### Using `<script>` tag
25
26The minified JS file can come from a downloaded copy or a CDN. When including
27it, make sure that the `<script>` tag for the plugin appears _after_ the
28include for [video.js](http://videojs.com/) (note that this plugin will look
29for `videojs` at `window.videojs`).
30
31There 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
51When using NPM/Browserify, first install the plugin.
52
53```
54npm install --save @silvermine/videojs-quality-selector
55```
56
57For `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
61var videojs = require('videojs');
62
63// The following registers the plugin with `videojs`
64require('@silvermine/videojs-quality-selector')(videojs);
65```
66
67Remember to also add the CSS to your build. With most bundlers you can:
68
69```js
70require('@silvermine/videojs-quality-selector/dist/css/quality-selector.css')
71```
72
73### Providing video sources
74
75Sources can be provided with either the `<source>` tag or via the `src` function on the
76instance 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
91player.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
113There are at least two ways to add the quality selector control to the player's control
114bar. The first is directly adding it via `addChild`. For example:
115
116```
117player.controlBar.addChild('QualitySelector');
118```
119
120The second option is to add the control via the player's options, for instance:
121
122```
123var options, player;
124
125options = {
126 controlBar: {
127 children: [
128 'playToggle',
129 'progressControl',
130 'volumePanel',
131 'qualitySelector',
132 'fullscreenToggle',
133 ],
134 },
135};
136
137player = videojs('video_1', options);
138```
139
140## How do I contribute?
141
142We genuinely appreciate external contributions. See [our extensive
143documentation](https://github.com/silvermine/silvermine-info#contributing) on how to
144contribute.
145
146
147## License
148
149This software is released under the MIT license. See [the license file](LICENSE) for more
150details.