wavesurfer.js

WaveSurfer Methods

After creating an instance of the player (with var wavesurfer = WaveSurfer.create({ ... })), you can call the following methods on it:

  • destroy() – Removes events, elements and disconnects Web Audio nodes.
  • empty() – Clears the waveform as if a zero-length audio is loaded.
  • getCurrentTime() – Returns current progress in seconds.
  • getDuration() – Returns the duration of an audio clip in seconds.
  • isPlaying() – Returns true if currently playing, false otherwise.
  • load(url) – Loads audio from URL via XHR. Returns XHR object.
  • loadBlob(url) – Loads audio from a Blob or File object.
  • on(eventName, callback) – Subscribes to an event. See WaveSurfer Events for the list of all events.
  • un(eventName, callback) – Unsubscribes from an event.
  • unAll() – Unsubscribes from all events.
  • pause() – Stops playback.
  • play([start[, end]]) – Starts playback from the current position. Optional start and end measured in seconds can be used to set the range of audio to play.
  • playPause() – Plays if paused, pauses if playing.
  • seekAndCenter(progress) – Seeks to a progress and centers view [0..1] (0 = beginning, 1 = end).
  • seekTo(progress) – Seeks to a progress [0..1] (0 = beginning, 1 = end).
  • setFilter(filters) - For inserting your own WebAudio nodes into the graph. See Connecting Filters below.
  • setPlaybackRate(rate) – Sets the speed of playback (0.5 is half speed, 1 is normal speed, 2 is double speed and so on).
  • setVolume(newVolume) – Sets the playback volume to a new value [0..1] (0 = silent, 1 = maximum).
  • skip(offset) – Skip a number of seconds from the current position (use a negative value to go backwards).
  • skipBackward() - Rewind skipLength seconds.
  • skipForward() - Skip ahead skipLength seconds.
  • stop() – Stops and goes to the beginning.
  • toggleMute() – Toggles the volume on and off.
  • toggleInteraction() – Toggle mouse interaction.
  • toggleScroll() – Toggles scrollParent.
  • zoom(pxPerSec) – Horiontally zooms the waveform in and out. The parameter is a number of horizontal pixels per second of audio. It also changes the parameter minPxPerSec and enables the scrollParent option.

Connecting Filters

You can insert your own Web Audio nodes into the graph using the method setFilter(). Example:

var lowpass = wavesurfer.backend.ac.createBiquadFilter();
wavesurfer.backend.setFilter(lowpass);
Fork me on GitHub