<div id="waveform"></div>
WaveSurfer
object.
var wavesurfer = WaveSurfer.create({
container: '#waveform'
});
npm install wavesurfer.jsTo use the library, you will need to include it from your code using CommonJS:
var WaveSurfer = require("wavesurfer.js");
Or ES6 syntax:
import WaveSurfer from "wavesurfer.js";
The only required parameter is container
. It can be either a unique CSS3 selector, or a DOM element.
scrollParent
option:
var wavesurfer = WaveSurfer.create({
container: '#waveform',
scrollParent: true
});
wavesurfer.load('../audio/song.mp3');
wavesurfer.load('http://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasdale_64kb.mp3');
ready
event.
ready
event, mentioned above, can be used like this:
wavesurfer.on('ready', function () {
wavesurfer.play();
});
You can also trigger various actions on the player, such as wavesurfer.pause()
, wavesurfer.skipForward()
, wavesurfer.toggleMute()
etc.
Take a look at the list of all available methods.
The provided Canvas
and MultiCanvas
renderers should support the vast majority of use cases, but wavesurfer.js
allows custom renderers to be
loaded. You can create your own renderer object (for example, by copying the Canvas
or MultiCanvas
renderer code into your own file and changing as necessary).
Note that custom renderer objects don't have to be added to the wavesurfer.js
repository, but you're welcome to raise a pull request if you think others will find your
renderer useful.
If you name your own renderer WaveSurfer.Drawer.MyDrawer
, then you can use the renderer by specifying the renderer
parameter as 'MyDrawer'
.