Home Reference Source Test
import MediaElementWebAudio from 'wavesurfer.js/src/mediaelement-webaudio.js'
public class | since 3.2.0 | source

MediaElementWebAudio

Extends:

util.ObserverWebAudioMediaElement → MediaElementWebAudio

MediaElementWebAudio backend: load audio via an HTML5 audio tag, but playback with the WebAudio API. The advantage here is that the html5 <audio> tag can perform range requests on the server and not buffer the entire file in one request, and you still get the filtering and scripting functionality of the webaudio API. Note that in order to use range requests and prevent buffering, you must provide peak data.

Constructor Summary

Public Constructor
public

Construct the backend

Method Summary

Public Methods
public

createMediaElementSource(mediaElement: HTMLMediaElement)

Create MediaElementSource node

since 3.2.0
public

This is called when wavesurfer is destroyed

public

init()

Initialise the backend, called in wavesurfer.createBackend()

public

play(start: *, end: *): *

Inherited Summary

From class WebAudio
public

ac: *

ac: Audio Context instance

public

analyser: provides audio analysis information

public

audioContext: allows to process audio with WebAudio API

public

Boolean indicating if the backend was destroyed.

public

gainNode: allows to control audio volume

public

scriptNode: allows processing audio

public

Create analyser node to perform audio analysis

public

Create ScriptProcessorNode to process audio

public

Create the gain node needed to control the playback volume.

public

This is called when wavesurfer is destroyed

public

Destroy all references with WebAudio, disconnecting audio nodes and closing Audio Context

public

getAudioContext(): AudioContext

Get the audio context used by this backend or create one

public

Returns the current time in seconds relative to the audio-clip's duration.

public

Used by wavesurfer.getDuration()

public

Get the offline audio context used by this backend or create one

public

getPeaks(length: number, first: number, last: number): number[] | Number<Array[]>

Compute the max and min value of the waveform when broken into <length> subranges.

public

Returns the current playback rate.

public

Get the position from 0 to 1

public

Get the playback position in seconds

public

Get the current volume

public

init()

Initialise the backend, called in wavesurfer.createBackend()

public

Used by wavesurfer.isPlaying() and wavesurfer.playPause()

public

load(buffer: Object)

Loaded a decoded audio buffer

public

pause()

Pauses the loaded audio.

public

play(start: number, end: number)

Plays the loaded audio region.

public

seekTo(start: number, end: number): {start: number, end: number}

Used by wavesurfer.seekTo()

public

setFilter(filters: ...AudioNode)

Unpacked setFilters()

public

setFilters(filters: AudioNode[])

Insert custom Web Audio nodes into the graph

public

setLength(length: number)

Set the rendered length (different from the length of the audio)

public

setPeaks(peaks: number[] | Number<Array[]>, duration: number)

Set pre-decoded peaks

public

Set a point in seconds for playback to stop at.

version 3.3.0
public

Set the audio source playback rate.

public

setSinkId(deviceId: string): Promise

Set the sink id for the media player

public

setVolume(value: number)

Set the audio volume

public

Does the browser support this backend

From class MediaElement
public
public

Create a timer to provide a more precise audioprocess event.

public

This is called when wavesurfer is destroyed

public

Returns the current time in seconds relative to the audio-clip's duration.

public

Used by wavesurfer.getDuration()

public

getPeaks(length: number, first: number, last: number): number[] | Number<Array[]>

Compute the max and min value of the waveform when broken into

<length> subranges.

public

Get the audio source playback rate.

public

Get the position from 0 to 1

public

Get the current volume

public

init()

Initialise the backend, called in wavesurfer.createBackend()

public

Used by wavesurfer.isPlaying() and wavesurfer.playPause()

public

load(url: string, container: HTMLElement, peaks: number[] | Number<Array[]>, preload: string)

Create media element with url as its source, and append to container element.

public

loadElt(elt: HTMLMediaElement, peaks: number[] | Number<Array[]>)

Load existing media element.

public

Pauses the loaded audio.

public

play(start: number, end: number): Promise

Plays the loaded audio region.

public

seekTo(start: number)

Used by wavesurfer.seekTo()

public

setMute(muted: boolean)

Enable or disable muted audio

since 4.0.0
public

Set the play end

public

Set the audio source playback rate.

public

setSinkId(deviceId: string): Promise

Set the sink id for the media player

public

setVolume(value: number)

Set the audio volume

Public Constructors

public constructor(params: WavesurferParams) source

Construct the backend

Override:

MediaElement#constructor

Params:

NameTypeAttributeDescription
params WavesurferParams

Wavesurfer parameters

Public Methods

public createMediaElementSource(mediaElement: HTMLMediaElement) since 3.2.0 source

Create MediaElementSource node

Params:

NameTypeAttributeDescription
mediaElement HTMLMediaElement

HTML5 Audio to load

public destroy() source

This is called when wavesurfer is destroyed

Override:

MediaElement#destroy

public init() source

Initialise the backend, called in wavesurfer.createBackend()

Override:

MediaElement#init

public play(start: *, end: *): * source

Plays the loaded audio region.

Override:

MediaElement#play

Params:

NameTypeAttributeDescription
start *
end *

Return:

*