UNPKG

11.7 kBMarkdownView Raw
1Video.js Wavesurfer
2===================
3
4A [video.js](http://www.videojs.com/) plugin that adds a navigable waveform
5for audio and video files, using the [wavesurfer.js](https://github.com/katspaugh/wavesurfer.js)
6library. Includes support for fullscreen mode and [real-time visualization of microphone
7input](#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
16Installation
17------------
18
19You can use [npm](https://www.npmjs.org) (`npm install videojs-wavesurfer`) to install the
20plugin, or [download it here](https://github.com/collab-project/videojs-wavesurfer/releases).
21If you want to try the examples, check [these instructions below](#examples).
22
23Since v2.0 this plugin is compatible with video.js 6.0 and wavesurfer.js 2.0 and
24newer. If you want to use this plugin with an older video.js or wavesurfer.js version,
25check the [archived releases](https://github.com/collab-project/videojs-wavesurfer/releases?after=1.3.7)
26for a 1.3.x or older release of this plugin.
27
28Take a look at the [changelog](./CHANGES.md) when upgrading from a previous
29version of videojs-wavesurfer.
30
31Using the Plugin
32----------------
33
34The 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
44The plugin automatically registers itself when the `videojs.wavesurfer.js`
45script is loaded:
46
47```html
48<script src="videojs.wavesurfer.js"></script>
49```
50
51Add an `audio` element:
52
53```html
54<audio id="myClip" class="video-js vjs-default-skin"></audio>
55```
56
57Or `video` element:
58
59```html
60<video id="myClip" class="video-js vjs-default-skin"></video>
61```
62
63Plugin Options
64--------------
65
66Configure the player using the video.js
67[options](https://github.com/videojs/video.js/blob/master/docs/guides/options.md),
68and 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
72var 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
94The 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
103Examples
104--------
105
106See 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
107the `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
109To try out the examples locally, checkout the repository using Git:
110```
111git clone https://github.com/collab-project/videojs-wavesurfer.git
112```
113
114And install the dependencies using npm:
115```
116cd videojs-wavesurfer
117npm install
118```
119
120Build the library and assets once:
121
122```
123npm run build
124```
125
126And start the local webserver for the examples:
127```
128npm run start
129```
130
131And open http://localhost:9999/examples/index.html in a browser.
132
133Methods
134-------
135
136Methods for this plugin documented below are available on the `wavesurfer` method
137of the video.js player instance. For example:
138
139```javascript
140player.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
157Other wavesurfer.js methods
158---------------------------
159
160You can access the wavesurfer instance, for example to call the
161wavesurfer.js `seekTo` method, by using the `surfer` property of the
162`wavesurfer` plugin instance:
163
164```javascript
165player.wavesurfer().surfer.seekTo(1);
166```
167
168Events
169------
170
171Plugin events that are available on the video.js player instance. For example:
172
173```javascript
174player.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
186Customizing controls
187--------------------
188
189To disable and hide specific controls, use the video.js `controlBar` option:
190
191```javascript
192controlBar: {
193 // hide fullscreen control
194 fullscreenToggle: false
195},
196```
197
198Responsive layout
199-----------------
200
201The `fluid` option for video.js will resize the player according to the size
202of the window.
203
204Configure the player; enable the video.js `'fluid'` option:
205
206```javascript
207fluid: true
208```
209
210See 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
214Text Tracks
215-----------
216
217Text tracks (or captions/subtitles) are a feature of HTML5 for displaying
218time-triggered text to the user. Video.js offers a cross-browser implementation
219of 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
224See 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
228Microphone plugin
229-----------------
230
231It's also possible to use a microphone for real-time rendering of the audio waveform. This
232uses the [microphone plugin](https://github.com/katspaugh/wavesurfer.js/blob/master/plugin/wavesurfer.microphone.js)
233that comes with wavesurfer.js.
234
235Include the additional `wavesurfer.microphone.js` plugin on your page.
236
237```html
238<script src="wavesurfer.microphone.min.js"></script>
239```
240
241Add an `audio` element:
242
243```html
244<audio id="myLiveAudio" class="video-js vjs-default-skin"></audio>
245```
246
247Configure the player: use the value `'live'` for the `src` option:
248
249```javascript
250var 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
267The microphone plugin has additional configuration
268[options](https://wavesurfer-js.org/plugins/microphone.html).
269
270See 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
275Change audio output or input device
276-----------------------------------
277
278If your device has multiple audio output devices, use `setAudioOutput(deviceId)` to change
279the active audio output device, and listen for the `audioOutputReady` event to be notified
280when the new output device is active.
281
282```javascript
283// change audio output device
284player.wavesurfer().setAudioOutput(deviceId);
285```
286
287See 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
291If your device has multiple audio input devices and you want to display
292these 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
297Using with React
298----------------
299
300The `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
305More features using other plugins
306---------------------------------
307
308The Video.js community created
309[lots of plugins](https://github.com/videojs/video.js/wiki/Plugins)
310that can be used to enhance the player's functionality. Plugins actually
311tested 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
317Development
318-----------
319
320Install dependencies using npm:
321
322```
323npm install
324```
325
326Build a minified version:
327
328```
329npm run build
330```
331
332Generated files are placed in the `dist` directory.
333
334During development:
335
336```
337npm run start
338```
339
340This will watch the source directory and rebuild when any changes
341are detected. It will also serve the files on http://127.0.0.1:9999.
342
343All commands for development are listed in the `package.json` file and
344are run using:
345
346```
347npm run <command>
348```
349
350
351License
352-------
353
354This work is licensed under the [MIT License](LICENSE).
355
356
357Donate
358------
359
360Please consider donating if you like this project. Bitcoin is accepted
361and can be sent to `3PmXCqUggtq7KUWPbpN8WhMnb1Mfb1jbq8`.