2017-06-21 00:43:49 +00:00
|
|
|
# Silvermine VideoJS Quality/Resolution Selector
|
|
|
|
|
2017-06-22 13:34:19 +00:00
|
|
|
[![Build Status](https://travis-ci.org/silvermine/videojs-quality-selector.svg?branch=master)](https://travis-ci.org/silvermine/videojs-quality-selector)
|
2017-06-21 00:43:49 +00:00
|
|
|
[![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)
|
2017-06-22 13:34:19 +00:00
|
|
|
[![Dependency Status](https://david-dm.org/silvermine/videojs-quality-selector.svg)](https://david-dm.org/silvermine/videojs-quality-selector)
|
|
|
|
[![Dev Dependency Status](https://david-dm.org/silvermine/videojs-quality-selector/dev-status.svg)](https://david-dm.org/silvermine/videojs-quality-selector?type=dev)
|
2017-06-21 00:43:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
## What is it?
|
|
|
|
|
|
|
|
A plugin for [videojs](http://videojs.com/) versions 6+ that adds a button to the control
|
|
|
|
bar which will allow the user to choose from available video qualities or resolutions.
|
|
|
|
|
|
|
|
|
|
|
|
## How do I use it?
|
|
|
|
|
2017-07-19 20:48:47 +00:00
|
|
|
There are three primary steps to use this plug-in: [(1) including](#includingrequiring),
|
|
|
|
[(2) providing sources](#providing-video-sources), and [(3) adding the component the to
|
|
|
|
`controlBar`](#adding-to-the-player). Please see the following for information on each
|
|
|
|
step.
|
|
|
|
|
|
|
|
### Including/Requiring
|
|
|
|
|
|
|
|
#### Using `<script>` tag
|
|
|
|
|
|
|
|
The minified JS file can come from a downloaded copy or a CDN. When including
|
|
|
|
it, make sure that the `<script>` tag for the plugin appears _after_ the
|
|
|
|
include for [video.js](http://videojs.com/) (note that this plugin will look
|
|
|
|
for `videojs` at `window.videojs`).
|
|
|
|
|
|
|
|
There is an example of this in
|
|
|
|
[`docs/demo/index.html`](./docs/demo/index.html).
|
|
|
|
|
2021-09-10 14:49:11 +00:00
|
|
|
##### From local file
|
2017-07-19 20:48:47 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
<script src="./path/to/video.min.js"></script>
|
|
|
|
<script src="./path/to/silvermine-videojs-quality-selector.min.js"></script>
|
|
|
|
```
|
|
|
|
|
2021-09-10 14:49:11 +00:00
|
|
|
##### From [`unpkg`](https://unpkg.com/@silvermine/videojs-quality-selector/)
|
2017-07-19 20:48:47 +00:00
|
|
|
|
|
|
|
```js
|
2019-11-23 20:31:57 +00:00
|
|
|
<link href="https://unpkg.com/@silvermine/videojs-quality-selector/dist/css/quality-selector.css" rel="stylesheet">
|
2017-07-19 20:48:47 +00:00
|
|
|
<script src="./path/to/video.min.js"></script>
|
2019-11-23 20:31:57 +00:00
|
|
|
<script src="https://unpkg.com/@silvermine/videojs-quality-selector/dist/js/silvermine-videojs-quality-selector.min.js"></script>
|
2017-07-19 20:48:47 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
#### Using `require`
|
|
|
|
|
|
|
|
When using NPM/Browserify, first install the plugin.
|
|
|
|
|
2021-09-10 14:49:11 +00:00
|
|
|
```bash
|
2019-11-23 20:31:57 +00:00
|
|
|
npm install --save @silvermine/videojs-quality-selector
|
2017-07-19 20:48:47 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
For `videojs` to use the plug-in, the plugin needs to register itself with the instance of
|
|
|
|
`videojs`. This can be accomplished by:
|
|
|
|
|
|
|
|
```js
|
|
|
|
var videojs = require('videojs');
|
|
|
|
|
|
|
|
// The following registers the plugin with `videojs`
|
2019-11-23 20:31:57 +00:00
|
|
|
require('@silvermine/videojs-quality-selector')(videojs);
|
2017-07-19 20:48:47 +00:00
|
|
|
```
|
|
|
|
|
2020-12-08 22:39:31 +00:00
|
|
|
Remember to also add the CSS to your build. With most bundlers you can:
|
|
|
|
|
|
|
|
```js
|
|
|
|
require('@silvermine/videojs-quality-selector/dist/css/quality-selector.css')
|
|
|
|
```
|
|
|
|
|
2017-07-19 20:48:47 +00:00
|
|
|
### Providing video sources
|
|
|
|
|
|
|
|
Sources can be provided with either the `<source>` tag or via the `src` function on the
|
|
|
|
instance of a `video.js` player.
|
|
|
|
|
|
|
|
#### Using `<source>`
|
|
|
|
|
|
|
|
```html
|
2022-02-22 00:13:30 +00:00
|
|
|
<video id="video_1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="268">
|
2017-07-19 20:48:47 +00:00
|
|
|
<source src="https://example.com/video_720.mp4" type="video/mp4" label="720P">
|
|
|
|
<source src="https://example.com/video_480.mp4" type="video/mp4" label="480P" selected="true">
|
|
|
|
<source src="https://example.com/video_360.mp4" type="video/mp4" label="360P">
|
|
|
|
</video>
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Using `player.src()`
|
2017-06-21 00:43:49 +00:00
|
|
|
|
|
|
|
```js
|
2017-07-19 20:48:47 +00:00
|
|
|
player.src([
|
|
|
|
{
|
|
|
|
src: 'https://example.com/video_720.mp4',
|
|
|
|
type: 'video/mp4',
|
|
|
|
label: '720P',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: 'https://example.com/video_480.mp4',
|
|
|
|
type: 'video/mp4',
|
|
|
|
label: '480P',
|
|
|
|
selected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: 'https://example.com/video_360.mp4',
|
|
|
|
type: 'video/mp4',
|
|
|
|
label: '360P',
|
|
|
|
},
|
|
|
|
]);
|
2017-06-21 00:43:49 +00:00
|
|
|
```
|
|
|
|
|
2017-07-19 20:48:47 +00:00
|
|
|
### Adding to the player
|
|
|
|
|
|
|
|
There are at least two ways to add the quality selector control to the player's control
|
|
|
|
bar. The first is directly adding it via `addChild`. For example:
|
|
|
|
|
2021-09-10 14:49:11 +00:00
|
|
|
```js
|
2022-02-22 00:13:30 +00:00
|
|
|
videojs('video_1', {}, function() {
|
|
|
|
var player = this;
|
|
|
|
|
|
|
|
player.controlBar.addChild('QualitySelector');
|
|
|
|
});
|
2017-07-19 20:48:47 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
The second option is to add the control via the player's options, for instance:
|
|
|
|
|
2021-09-10 14:49:11 +00:00
|
|
|
```js
|
2017-07-19 20:48:47 +00:00
|
|
|
var options, player;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
controlBar: {
|
|
|
|
children: [
|
|
|
|
'playToggle',
|
|
|
|
'progressControl',
|
|
|
|
'volumePanel',
|
|
|
|
'qualitySelector',
|
|
|
|
'fullscreenToggle',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
player = videojs('video_1', options);
|
|
|
|
```
|
2017-06-21 00:43:49 +00:00
|
|
|
|
|
|
|
## How do I contribute?
|
|
|
|
|
|
|
|
We genuinely appreciate external contributions. See [our extensive
|
|
|
|
documentation](https://github.com/silvermine/silvermine-info#contributing) on how to
|
|
|
|
contribute.
|
|
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
This software is released under the MIT license. See [the license file](LICENSE) for more
|
|
|
|
details.
|