Function
Static Public Summary | ||
public |
Calculate FFT - Based on https://github.com/corbanbrook/dsp.js |
|
public |
Get the largest absolute value in an array |
since 4.3.0 |
public |
Returns a number limited to the given range. |
|
public |
Load a file using |
|
public |
Create a function which will be called at the next requestAnimationFrame cycle |
|
public |
Get a random prefixed ID |
|
public |
Ignores device silence mode when using the |
since 5.2.0 |
public |
Get the largest value |
|
public |
Get the smallest value |
|
public |
preventClick(values: object) Starts listening for click event and prevent propagation |
|
public |
style(el: HTMLElement, styles: Object): HTMLElement Apply a map of styles to an element |
|
public |
withOrientation(target: object, vertical: bool): Proxy Returns an appropriately oriented object based on vertical. |
since 5.0.0 |
Static Public
public FFT(bufferSize: Number, sampleRate: Number, windowFunc: Function, alpha: Number) source
import FFT from 'wavesurfer.js/src/plugin/spectrogram/fft.js'
Calculate FFT - Based on https://github.com/corbanbrook/dsp.js
public absMax(values: Array): Number since 4.3.0 source
import absMax from 'wavesurfer.js/src/util/absMax.js'
Get the largest absolute value in an array
Params:
Name | Type | Attribute | Description |
values | Array | Array of numbers |
Example:
console.log(max([-3, 2, 1]), max([-3, 2, 4])); // logs 3 4
public clamp(val: number, min: number, max: number): number source
import clamp from 'wavesurfer.js/src/util/clamp.js'
Returns a number limited to the given range.
public fetchFile(options: object): Observer source
import fetchFile from 'wavesurfer.js/src/util/fetch.js'
Load a file using fetch
.
Params:
Name | Type | Attribute | Description |
options | object | Request options to use. See example below. |
Example:
// default options
let options = {
url: undefined,
method: 'GET',
mode: 'cors',
credentials: 'same-origin',
cache: 'default',
responseType: 'json',
requestHeaders: [],
redirect: 'follow',
referrer: 'client'
};
// override some options
options.url = '../media/demo.wav';
// available types: 'arraybuffer', 'blob', 'json' or 'text'
options.responseType = 'arraybuffer';
// make fetch call
let request = util.fetchFile(options);
// listen for events
request.on('progress', e => {
console.log('progress', e);
});
request.on('success', data => {
console.log('success!', data);
});
request.on('error', e => {
console.warn('fetchFile error: ', e);
});
public frame(func: function): func source
import frame from 'wavesurfer.js/src/util/frame.js'
Create a function which will be called at the next requestAnimationFrame cycle
Params:
Name | Type | Attribute | Description |
func | function | The function to call |
Return:
func | The function wrapped within a requestAnimationFrame |
public getId(prefix: String): String source
import getId from 'wavesurfer.js/src/util/get-id.js'
Get a random prefixed ID
Params:
Name | Type | Attribute | Description |
prefix | String | Prefix to use. Default is |
Example:
console.log(getId()); // logs 'wavesurfer_b5pors4ru6g'
let prefix = 'foo-';
console.log(getId(prefix)); // logs 'foo-b5pors4ru6g'
public ignoreSilenceMode() since 5.2.0 source
import ignoreSilenceMode from 'wavesurfer.js/src/util/silence-mode.js'
Ignores device silence mode when using the WebAudio
backend.
Many mobile devices contain a hardware button to mute the ringtone for incoming
calls and messages. Unfortunately, on some platforms like iOS, this also mutes
wavesurfer's audio when using the WebAudio
backend. This function creates a
temporary <audio>
element that makes sure the WebAudio backend keeps playing
when muting the device ringer.
public max(values: Array): Number source
import max from 'wavesurfer.js/src/util/max.js'
Get the largest value
Params:
Name | Type | Attribute | Description |
values | Array | Array of numbers |
Example:
console.log(max([1, 2, 3])); // logs 3
public min(values: Array): Number source
import min from 'wavesurfer.js/src/util/min.js'
Get the smallest value
Params:
Name | Type | Attribute | Description |
values | Array | Array of numbers |
Example:
console.log(min([1, 2, 3])); // logs 1
public preventClick(values: object) source
import preventClick from 'wavesurfer.js/src/util/prevent-click.js'
Starts listening for click event and prevent propagation
Params:
Name | Type | Attribute | Description |
values | object | Values |
public style(el: HTMLElement, styles: Object): HTMLElement source
import style from 'wavesurfer.js/src/util/style.js'
Apply a map of styles to an element
Params:
Name | Type | Attribute | Description |
el | HTMLElement | The element that the styles will be applied to |
|
styles | Object | The map of propName: attribute, both are used as-is |
public withOrientation(target: object, vertical: bool): Proxy since 5.0.0 source
import withOrientation from 'wavesurfer.js/src/util/orientation.js'
Returns an appropriately oriented object based on vertical. If vertical is true, attribute getting and setting will be mapped through verticalPropMap, so that e.g. getting the object's .width will give its .height instead. Certain methods of an oriented object will return oriented objects as well. Oriented objects can't be added to the DOM directly since they are Proxy objects and thus fail typechecks. Use domElement to get the actual element for this.
Params:
Name | Type | Attribute | Description |
target | object | The object to be wrapped and oriented |
|
vertical | bool | Whether the element is oriented vertically |