Home Reference Source
public class | source

Init

The HTML initialisation API is not part of the main library bundle file and must be additionally included.

The API attaches wavesurfer instances to all <wavesurfer> (can be customised), parsing their data- attributes to construct an options object for initialisation. Among other things it can dynamically load plugin code.

The automatic initialisation can be prevented by setting the window.WS_StopAutoInit flag to true. The html-init[.min].js file exports the Init class, which can be called manually.

Site-wide defaults can be added by setting window.WS_InitOptions.

Example:

<!-- with minimap and timeline plugin -->
<wavesurfer
  data-url="../media/demo.wav"
  data-plugins="minimap,timeline"
  data-minimap-height="30"
  data-minimap-wave-color="#ddd"
  data-minimap-progress-color="#999"
  data-timeline-font-size="13px"
  data-timeline-container="#timeline"
>
</wavesurfer>
<div id="timeline"></div>

<!-- with regions plugin -->
<wavesurfer
  data-url="../media/demo.wav"
  data-plugins="regions"
  data-regions-regions='[{"start": 1,"end": 3,"color": "hsla(400, 100%, 30%, 0.5)"}]'
>
</wavesurfer>

Constructor Summary

Public Constructor
public

constructor(WaveSurfer: WaveSurfer, params: InitParams)

Instantiate Init class and initialize elements

Member Summary

Public Members
public

containers: NodeList

The nodes that should have instances attached to them

public

An array of wavesurfer instances

Method Summary

Public Methods
public

Initialize all container elements

public

Initialize a single container element and add to this.instances

Public Constructors

public constructor(WaveSurfer: WaveSurfer, params: InitParams) source

Instantiate Init class and initialize elements

This is done automatically if window is defined and window.WS_StopAutoInit is not set to true

Params:

NameTypeAttributeDescription
WaveSurfer WaveSurfer

The WaveSurfer library object

params InitParams

initialisation options

Public Members

public containers: NodeList source

The nodes that should have instances attached to them

public instances: Object[] source

An array of wavesurfer instances

Public Methods

public initAllEls() source

Initialize all container elements

public initEl(el: HTMLElement, plugins: PluginDefinition[]): Object source

Initialize a single container element and add to this.instances

Params:

NameTypeAttributeDescription
el HTMLElement

The container to instantiate wavesurfer to

plugins PluginDefinition[]

An Array of plugin names to initialize with

Return:

Object

Wavesurfer instance