JSPM

  • Created
  • Published
  • Downloads 23184
  • Score
    100M100P100Q148191F
  • License MIT

video.js plugin that adds a navigable waveform for audio and video files.

Package Exports

  • videojs-wavesurfer

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (videojs-wavesurfer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Video.js Wavesurfer

A video.js plugin that adds a navigable waveform for audio and video files, using the wavesurfer.js library. Includes support for fullscreen mode and real-time visualization of microphone input.

Screenshot

npm version npm License Build Status

Installation

You can use bower (bower install videojs-wavesurfer) or npm (npm install videojs-wavesurfer) to install the plugin, or download it here.

Since v1.0 this plugin is compatible with video.js 5.0 and newer. If you want to use this plugin with an older video.js 4.x version, check the archived releases for a 0.9.x or older release of this plugin.

Take a look at the changelog when upgrading from a previous version of videojs-wavesurfer.

Using the Plugin

The plugin depends on the video.js and wavesurfer.js libraries:

<link href="video-js.min.css" rel="stylesheet">
<script src="video.min.js"></script>

<script src="wavesurfer.min.js"></script>

The plugin automatically registers itself when the videojs.wavesurfer.js script is loaded:

<script src="videojs.wavesurfer.js"></script>

Add an audio element:

<audio id="myClip" class="video-js vjs-default-skin"></audio>

Or video element:

<video id="myClip" class="video-js vjs-default-skin"></video>

Plugin Options

Configure the player using the video.js options, and enable the plugin by adding a wavesurfer entry with the related wavesurfer.js options:

var player = videojs('myClip',
{
    controls: true,
    autoplay: true,
    loop: false,
    width: 600,
    height: 300,
    plugins: {
        wavesurfer: {
            src: 'media/hal.wav',
            msDisplayMax: 10,
            debug: true,
            waveColor: 'grey',
            progressColor: 'black',
            cursorColor: 'black',
            hideScrollbar: true
        }
    }
});

See the full audio example (demo or source) and the video example (demo or source).

The additional options for this plugin are:

option type default description
src string null The URL of the audio/video file or 'live' when using the microphone plugin.
debug boolean false Display internal log messages using the videojs.log method.
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.

Methods

Methods for this plugin documented below are available on the waveform object of the video.js player instance. For example:

player.waveform.destroy();
Method Description
destroy Destroys the wavesurfer instance and children (including the video.js player).
load(url) Load the clip at url. Also supports loading File or Blob objects.
setVolume(level) Set the volume level.
play Start playback.
pause Pause playback.
exportImage(format, quality) Save waveform image as data URI. Default format is 'image/png'.

Other wavesurfer.js methods

You can access the wavesurfer instance, for example to call the zoom method, by using the waveform.surfer property on the player instance:

player.waveform.surfer.zoom(2);

Events

Plugin events that are available on the video.js player instance. For example:

player.on('waveReady', function()
{
    console.log('waveform is ready!');
});
Event Description
waveReady Audio is loaded, decoded and the waveform is drawn.

Customizing controls

To disable and hide specific controls, use the video.js controlBar option:

controlBar: {
    // hide fullscreen control
    fullscreenToggle: false
},

Microphone plugin

It's also possible to use a microphone for real-time rendering of the audio waveform. This uses the microphone plugin that comes with wavesurfer.js.

Include the additional wavesurfer.microphone.js plugin on your page.

<script src="wavesurfer.microphone.min.js"></script>

Add an audio element:

<audio id="myLiveAudio" class="video-js vjs-default-skin"></audio>

Configure the player: use the value 'live' for the src option:

var player = videojs('myLiveAudio',
{
    controls: true,
    width: 600,
    height: 300,
    plugins: {
        wavesurfer: {
            src: 'live',
            debug: true,
            waveColor: 'black',
            cursorWidth: 0,
            interact: false
        }
    }
});

The microphone plugin has additional configuration options.

See the full live example (demo or source).

More features using other plugins

The Video.js community created lots of plugins that can be used to enhance the player's functionality. Plugins actually tested with videojs-wavesurfer:

  • videojs-record - Adds support for recording audio/video/image files.

Contributing

Install grunt-cli:

sudo npm install -g grunt-cli

Install dependencies using npm:

npm install

Build a minified version:

grunt

Generated files are placed in the dist directory.

License

This work is licensed under the MIT License.