Home Reference Source
import MediaElement from 'wavesurfer.js/src/mediaelement.js'
public class | source

MediaElement

Extends:

ObserverWebAudio → MediaElement

Direct Subclass:

MediaElementWebAudio

MediaElement backend

Constructor Summary

Public Constructor
public

Construct the backend

Member Summary

Public Members
public

Method Summary

Public Methods
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

Inherited Summary

From class Observer
public
public

fireEvent(event: string, args: ...any)

Manually fire an event

public

Attach a handler function for an event.

public

once(event: string, handler: function): ListenerDescriptor

Attach a handler to an event.

public

Disable firing a list of events by name.

since 4.0.0
public

un(event: string, fn: function)

Remove an event handler.

public

unAll()

Remove all event handlers.

From class WebAudio
public static

scriptBufferSize: size of the processing buffer

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

Public Constructors

public constructor(params: WavesurferParams) source

Construct the backend

Override:

WebAudio#constructor

Params:

NameTypeAttributeDescription
params WavesurferParams

Wavesurfer parameters

Public Members

public destroyed: boolean source

Boolean indicating if the backend was destroyed.

Override:

WebAudio#destroyed

Public Methods

public createTimer() source

Create a timer to provide a more precise audioprocess event.

public destroy() source

This is called when wavesurfer is destroyed

Override:

WebAudio#destroy

public getCurrentTime(): number source

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

Override:

WebAudio#getCurrentTime

Return:

number

Current time

public getDuration(): number source

Used by wavesurfer.getDuration()

Override:

WebAudio#getDuration

Return:

number

Duration

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

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

<length> subranges.

Override:

WebAudio#getPeaks

Params:

NameTypeAttributeDescription
length number

How many subranges to break the waveform into.

first number

First sample in the required range.

last number

Last sample in the required range.

Return:

number[] | Number<Array[]>

Array of 2*<length> peaks or array of arrays of peaks consisting of (max, min) values for each subrange.

public getPlaybackRate(): number source

Get the audio source playback rate.

Override:

WebAudio#getPlaybackRate

Return:

number

Playback rate

public getPlayedPercents(): number source

Get the position from 0 to 1

Override:

WebAudio#getPlayedPercents

Return:

number

Current position

public getVolume(): number source

Get the current volume

Override:

WebAudio#getVolume

Return:

number

value A floating point value between 0 and 1.

public init() source

Initialise the backend, called in wavesurfer.createBackend()

Override:

WebAudio#init

public isPaused(): boolean source

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

Override:

WebAudio#isPaused

Return:

boolean

Media paused or not

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

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

Override:

WebAudio#load

Params:

NameTypeAttributeDescription
url string

Path to media file

container HTMLElement

HTML element

peaks number[] | Number<Array[]>

Array of peak data

preload string

HTML 5 preload attribute value

Throw:

*

Will throw an error if the url argument is not a valid media element.

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

Load existing media element.

Params:

NameTypeAttributeDescription
elt HTMLMediaElement

HTML5 Audio or Video element

peaks number[] | Number<Array[]>

Array of peak data

public pause(): Promise source

Pauses the loaded audio.

Override:

WebAudio#pause

Return:

Promise

Result

Emit:

*

MediaElement#pause

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

Plays the loaded audio region.

Override:

WebAudio#play

Params:

NameTypeAttributeDescription
start number

Start offset in seconds, relative to the beginning of a clip.

end number

When to stop, relative to the beginning of a clip.

Return:

Promise

Result

Emit:

*

MediaElement#play

public seekTo(start: number) source

Used by wavesurfer.seekTo()

Override:

WebAudio#seekTo

Params:

NameTypeAttributeDescription
start number

Position to start at in seconds

public setMute(muted: boolean) since 4.0.0 source

Enable or disable muted audio

Params:

NameTypeAttributeDescription
muted boolean

Specify true to mute audio.

public setPlayEnd(end: number) source

Set the play end

Override:

WebAudio#setPlayEnd

Params:

NameTypeAttributeDescription
end number

Where to end

public setPlaybackRate(value: number) source

Set the audio source playback rate.

Override:

WebAudio#setPlaybackRate

Params:

NameTypeAttributeDescription
value number

Playback rate

public setSinkId(deviceId: string): Promise source

Set the sink id for the media player

Override:

WebAudio#setSinkId

Params:

NameTypeAttributeDescription
deviceId string

String value representing audio device id.

Return:

Promise

A Promise that resolves to undefined when there are no errors.

public setVolume(value: number) source

Set the audio volume

Override:

WebAudio#setVolume

Params:

NameTypeAttributeDescription
value number

A floating point value between 0 and 1.