1 | Video.js Wavesurfer
|
2 | ===================
|
3 |
|
4 | A [video.js](http://www.videojs.com/) plugin that adds a navigable waveform
|
5 | for audio and video files, using the [wavesurfer.js](https://github.com/katspaugh/wavesurfer.js)
|
6 | library. Includes support for fullscreen mode and [real-time visualization of microphone
|
7 | input](#microphone-plugin).
|
8 |
|
9 | ![Screenshot](examples/img/screenshot.png?raw=true "Screenshot")
|
10 |
|
11 | [![npm version](https://img.shields.io/npm/v/videojs-wavesurfer.svg?style=flat)](https://www.npmjs.com/package/videojs-wavesurfer)
|
12 | [![npm](https://img.shields.io/npm/dm/videojs-wavesurfer.svg)](https://github.com/collab-project/videojs-wavesurfer/releases)
|
13 | [![License](https://img.shields.io/npm/l/videojs-wavesurfer.svg)](LICENSE)
|
14 | [![Build Status](https://travis-ci.org/collab-project/videojs-wavesurfer.svg?branch=master)](https://travis-ci.org/collab-project/videojs-wavesurfer)
|
15 |
|
16 | Installation
|
17 | ------------
|
18 |
|
19 | You can use [npm](https://www.npmjs.org) (`npm install videojs-wavesurfer`) to install the
|
20 | plugin, or [download it here](https://github.com/collab-project/videojs-wavesurfer/releases).
|
21 | If you want to try the examples, check [these instructions below](#examples).
|
22 |
|
23 | Since v2.0 this plugin is compatible with video.js 6.0 and wavesurfer.js 2.0 and
|
24 | newer. If you want to use this plugin with an older video.js or wavesurfer.js version,
|
25 | check the [archived releases](https://github.com/collab-project/videojs-wavesurfer/releases?after=1.3.7)
|
26 | for a 1.3.x or older release of this plugin.
|
27 |
|
28 | Take a look at the [changelog](./CHANGES.md) when upgrading from a previous
|
29 | version of videojs-wavesurfer.
|
30 |
|
31 | Using the Plugin
|
32 | ----------------
|
33 |
|
34 | The plugin depends on the video.js and wavesurfer.js libraries:
|
35 |
|
36 | ```html
|
37 | <link href="video-js.min.css" rel="stylesheet">
|
38 | <link href="videojs.wavesurfer.css" rel="stylesheet">
|
39 | <script src="video.min.js"></script>
|
40 |
|
41 | <script src="wavesurfer.min.js"></script>
|
42 | ```
|
43 |
|
44 | The plugin automatically registers itself when the `videojs.wavesurfer.js`
|
45 | script is loaded:
|
46 |
|
47 | ```html
|
48 | <script src="videojs.wavesurfer.js"></script>
|
49 | ```
|
50 |
|
51 | Add an `audio` element:
|
52 |
|
53 | ```html
|
54 | <audio id="myClip" class="video-js vjs-default-skin"></audio>
|
55 | ```
|
56 |
|
57 | Or `video` element:
|
58 |
|
59 | ```html
|
60 | <video id="myClip" class="video-js vjs-default-skin"></video>
|
61 | ```
|
62 |
|
63 | Plugin Options
|
64 | --------------
|
65 |
|
66 | Configure the player using the video.js
|
67 | [options](https://github.com/videojs/video.js/blob/master/docs/guides/options.md),
|
68 | and enable the plugin by adding a `wavesurfer` entry with the related wavesurfer.js
|
69 | [options](https://wavesurfer-js.org/docs/options.html):
|
70 |
|
71 | ```javascript
|
72 | var player = videojs('myClip',
|
73 | {
|
74 | controls: true,
|
75 | autoplay: true,
|
76 | loop: false,
|
77 | fluid: false,
|
78 | width: 600,
|
79 | height: 300,
|
80 | plugins: {
|
81 | wavesurfer: {
|
82 | src: 'media/hal.wav',
|
83 | msDisplayMax: 10,
|
84 | debug: true,
|
85 | waveColor: 'grey',
|
86 | progressColor: 'black',
|
87 | cursorColor: 'black',
|
88 | hideScrollbar: true
|
89 | }
|
90 | }
|
91 | });
|
92 | ```
|
93 |
|
94 | The additional options for this plugin are:
|
95 |
|
96 | | option | type | default | description |
|
97 | | --- | --- | --- | --- |
|
98 | | `src` | string | `null` | The URL of the audio/video file or `'live'` when [using the microphone plugin](#microphone-plugin).|
|
99 | | `peaks` | string | `null` | The URL of the JSON file with peak data corresponding to the source audio/video file. This allows the waveform to be created from pre-rendered peak data. This file can be generated using the [bbc/audiowaveform](https://github.com/bbc/audiowaveform) utility. |
|
100 | | `debug` | boolean | `false` | Display internal log messages using the `videojs.log` method. |
|
101 | | `msDisplayMax` | float | `3` | Indicates the number of seconds that is considered the boundary value for displaying milliseconds in the time controls. An audio clip with a total length of 2 seconds and a `msDisplayMax` of 3 will use the format `M:SS:MMM`. Clips with a duration that is longer than `msDisplayMax` will be displayed as `M:SS` or `HH:MM:SS`.|
|
102 |
|
103 | Examples
|
104 | --------
|
105 |
|
106 | See the full `audio` example ([demo](https://collab-project.github.io/videojs-wavesurfer/examples/index.html) or [source](https://github.com/collab-project/videojs-wavesurfer/blob/master/examples/index.html)) and
|
107 | the `video` example ([demo](https://collab-project.github.io/videojs-wavesurfer/examples/video.html) or [source](https://github.com/collab-project/videojs-wavesurfer/blob/master/examples/video.html)).
|
108 |
|
109 | To try out the examples locally, checkout the repository using Git:
|
110 | ```
|
111 | git clone https://github.com/collab-project/videojs-wavesurfer.git
|
112 | ```
|
113 |
|
114 | And install the dependencies using npm:
|
115 | ```
|
116 | cd videojs-wavesurfer
|
117 | npm install
|
118 | ```
|
119 |
|
120 | Build the library and assets once:
|
121 |
|
122 | ```
|
123 | npm run build
|
124 | ```
|
125 |
|
126 | And start the local webserver for the examples:
|
127 | ```
|
128 | npm run start
|
129 | ```
|
130 |
|
131 | And open http://localhost:9999/examples/index.html in a browser.
|
132 |
|
133 | Methods
|
134 | -------
|
135 |
|
136 | Methods for this plugin documented below are available on the `wavesurfer` method
|
137 | of the video.js player instance. For example:
|
138 |
|
139 | ```javascript
|
140 | player.on('ready', function() {
|
141 | player.wavesurfer().destroy();
|
142 | });
|
143 | ```
|
144 |
|
145 | | Method | Description |
|
146 | | --- | --- |
|
147 | | `destroy` | Destroys the wavesurfer instance and children (including the video.js player). |
|
148 | | `load(url)` | Load the clip at `url`. Also supports loading [File](https://developer.mozilla.org/nl/docs/Web/API/File) or [Blob](https://developer.mozilla.org/nl/docs/Web/API/Blob) objects. |
|
149 | | `setVolume(level)` | Set the volume level (value between 0.0 and 1.0). |
|
150 | | `play` | Start playback. |
|
151 | | `pause` | Pause playback. |
|
152 | | `getDuration` | Get the length of the stream in seconds. Returns 0 if no stream is available (yet). |
|
153 | | `getCurrentTime` | Get the current time (in seconds) of the stream during playback. Returns 0 if no stream is available (yet). |
|
154 | | `exportImage(format, quality)` | Save waveform image as data URI. Default format is `'image/png'`. |
|
155 | | `setAudioOutput(deviceId)` | Change the audio output device using its [deviceId](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/deviceId). |
|
156 |
|
157 | Other wavesurfer.js methods
|
158 | ---------------------------
|
159 |
|
160 | You can access the wavesurfer instance, for example to call the
|
161 | wavesurfer.js `seekTo` method, by using the `surfer` property of the
|
162 | `wavesurfer` plugin instance:
|
163 |
|
164 | ```javascript
|
165 | player.wavesurfer().surfer.seekTo(1);
|
166 | ```
|
167 |
|
168 | Events
|
169 | ------
|
170 |
|
171 | Plugin events that are available on the video.js player instance. For example:
|
172 |
|
173 | ```javascript
|
174 | player.on('waveReady', function(event) {
|
175 | console.log('waveform is ready!');
|
176 | });
|
177 | ```
|
178 |
|
179 | | Event | Description |
|
180 | | --- | --- |
|
181 | | `waveReady` | Audio is loaded, decoded and the waveform is drawn. |
|
182 | | `playbackFinish` | Audio playback finished. |
|
183 | | `audioOutputReady` | Audio output was changed and is now active. |
|
184 | | `error` | Error occurred. |
|
185 |
|
186 | Customizing controls
|
187 | --------------------
|
188 |
|
189 | To disable and hide specific controls, use the video.js `controlBar` option:
|
190 |
|
191 | ```javascript
|
192 | controlBar: {
|
193 | // hide fullscreen control
|
194 | fullscreenToggle: false
|
195 | },
|
196 | ```
|
197 |
|
198 | Responsive layout
|
199 | -----------------
|
200 |
|
201 | The `fluid` option for video.js will resize the player according to the size
|
202 | of the window.
|
203 |
|
204 | Configure the player; enable the video.js `'fluid'` option:
|
205 |
|
206 | ```javascript
|
207 | fluid: true
|
208 | ```
|
209 |
|
210 | See the full `fluid` example
|
211 | ([demo](https://collab-project.github.io/videojs-wavesurfer/examples/fluid.html) or
|
212 | [source](https://github.com/collab-project/videojs-wavesurfer/blob/master/examples/fluid.html)).
|
213 |
|
214 | Text Tracks
|
215 | -----------
|
216 |
|
217 | Text tracks (or captions/subtitles) are a feature of HTML5 for displaying
|
218 | time-triggered text to the user. Video.js offers a cross-browser implementation
|
219 | of text tracks. For more information, check the
|
220 | [documentation](https://github.com/videojs/video.js/blob/master/docs/guides/text-tracks.md).
|
221 |
|
222 | ![Text tracks screenshot](examples/img/text-tracks.png?raw=true "Text tracks screenshot")
|
223 |
|
224 | See the full `texttrack` example
|
225 | ([demo](https://collab-project.github.io/videojs-wavesurfer/examples/texttrack.html) or
|
226 | [source](https://github.com/collab-project/videojs-wavesurfer/blob/master/examples/texttrack.html)).
|
227 |
|
228 | Microphone plugin
|
229 | -----------------
|
230 |
|
231 | It's also possible to use a microphone for real-time rendering of the audio waveform. This
|
232 | uses the [microphone plugin](https://github.com/katspaugh/wavesurfer.js/blob/master/plugin/wavesurfer.microphone.js)
|
233 | that comes with wavesurfer.js.
|
234 |
|
235 | Include the additional `wavesurfer.microphone.js` plugin on your page.
|
236 |
|
237 | ```html
|
238 | <script src="wavesurfer.microphone.min.js"></script>
|
239 | ```
|
240 |
|
241 | Add an `audio` element:
|
242 |
|
243 | ```html
|
244 | <audio id="myLiveAudio" class="video-js vjs-default-skin"></audio>
|
245 | ```
|
246 |
|
247 | Configure the player: use the value `'live'` for the `src` option:
|
248 |
|
249 | ```javascript
|
250 | var player = videojs('myLiveAudio', {
|
251 | controls: true,
|
252 | width: 600,
|
253 | height: 300,
|
254 | plugins: {
|
255 | wavesurfer: {
|
256 | src: 'live',
|
257 | debug: true,
|
258 | waveColor: 'black',
|
259 | cursorWidth: 0,
|
260 | interact: false,
|
261 | hideScrollbar: true
|
262 | }
|
263 | }
|
264 | });
|
265 | ```
|
266 |
|
267 | The microphone plugin has additional configuration
|
268 | [options](https://wavesurfer-js.org/plugins/microphone.html).
|
269 |
|
270 | See the full `live` example
|
271 | ([demo](https://collab-project.github.io/videojs-wavesurfer/examples/live.html) or
|
272 | [source](https://github.com/collab-project/videojs-wavesurfer/blob/master/examples/live.html)).
|
273 |
|
274 |
|
275 | Change audio output or input device
|
276 | -----------------------------------
|
277 |
|
278 | If your device has multiple audio output devices, use `setAudioOutput(deviceId)` to change
|
279 | the active audio output device, and listen for the `audioOutputReady` event to be notified
|
280 | when the new output device is active.
|
281 |
|
282 | ```javascript
|
283 | // change audio output device
|
284 | player.wavesurfer().setAudioOutput(deviceId);
|
285 | ```
|
286 |
|
287 | See the full `output` example
|
288 | ([demo](https://collab-project.github.io/videojs-wavesurfer/examples/output.html) or
|
289 | [source](https://github.com/collab-project/videojs-wavesurfer/blob/master/examples/output.html)).
|
290 |
|
291 | If your device has multiple audio input devices and you want to display
|
292 | these devices and allow the user to choose one, check out the the full `input` example
|
293 | ([demo](https://collab-project.github.io/videojs-wavesurfer/examples/input.html) or
|
294 | [source](https://github.com/collab-project/videojs-wavesurfer/blob/master/examples/input.html)).
|
295 |
|
296 |
|
297 | Using with React
|
298 | ----------------
|
299 |
|
300 | The `react` example shows how to integrate this plugin in a [React](https://reactjs.org) component
|
301 | ([demo](https://collab-project.github.io/videojs-wavesurfer/examples/react/index.html) or
|
302 | [source](https://github.com/collab-project/videojs-wavesurfer/blob/master/examples/react/index.html)).
|
303 |
|
304 |
|
305 | More features using other plugins
|
306 | ---------------------------------
|
307 |
|
308 | The Video.js community created
|
309 | [lots of plugins](https://github.com/videojs/video.js/wiki/Plugins)
|
310 | that can be used to enhance the player's functionality. Plugins actually
|
311 | tested with `videojs-wavesurfer`:
|
312 |
|
313 | - [videojs-record](https://github.com/collab-project/videojs-record) - Adds
|
314 | support for recording audio/video/image files.
|
315 |
|
316 |
|
317 | Development
|
318 | -----------
|
319 |
|
320 | Install dependencies using npm:
|
321 |
|
322 | ```
|
323 | npm install
|
324 | ```
|
325 |
|
326 | Build a minified version:
|
327 |
|
328 | ```
|
329 | npm run build
|
330 | ```
|
331 |
|
332 | Generated files are placed in the `dist` directory.
|
333 |
|
334 | During development:
|
335 |
|
336 | ```
|
337 | npm run start
|
338 | ```
|
339 |
|
340 | This will watch the source directory and rebuild when any changes
|
341 | are detected. It will also serve the files on http://127.0.0.1:9999.
|
342 |
|
343 | All commands for development are listed in the `package.json` file and
|
344 | are run using:
|
345 |
|
346 | ```
|
347 | npm run <command>
|
348 | ```
|
349 |
|
350 |
|
351 | License
|
352 | -------
|
353 |
|
354 | This work is licensed under the [MIT License](LICENSE).
|
355 |
|
356 |
|
357 | Donate
|
358 | ------
|
359 |
|
360 | Please consider donating if you like this project. Bitcoin is accepted
|
361 | and can be sent to `3PmXCqUggtq7KUWPbpN8WhMnb1Mfb1jbq8`.
|