AudioTrack

An AudioTrack instance represents a single audio track of a Node.
A Node may have one or more audio tracks, which can be accessed via the getAudioTracks method.
An audio track’s muted state can be toggled and its volume can be set.
It is also an event emitter, exposing the on/once/off/trigger methods and triggering a volumechange event.

Properties

audioTrack.muted : boolean
property

True if this audio track is muted, and false otherwise.
Setting this value will cause a volumechange event to be triggered.

See: volume, volumechange
Example

function toggleTrack(audioTrack) {
    audioTrack.muted = !audioTrack.muted;
}

audioTrack.volume : number
property

The audio track’s volume, from 0.0 (silent) to 1.0 (loudest).
Setting this value will change the volume and cause a volumechange event to be triggered.

See: muted, volumechange

audioTrack.node : Node
propertyreadonly

The Node that this audio track belongs to.

See: index

audioTrack.index : number
propertyreadonly

The 0-based index of this audio track in the node it belongs to.

See: node

Methods

audioTrack.on(evt, listener)
method

Adds a listener function to the specified event on the node.
If the listener function returns true then it will be removed after it is called.
If you pass a regular expression as the event name then the listener will be added to all events that match it.

See: once, off, trigger

Param Type Description
evt string | RegExp Name of the event to attach the listener to.
listener function Method to be called when the event is triggered. If the function returns true, then it will be removed after calling.

audioTrack.once(evt, listener)
method

Adds a listener function to the event on the node, this listener will automatically be removed after first execution.
If you pass a regular expression as the event name then the listener will be added to all events that match it.

See: on, off, trigger

Param Type Description
evt string | RegExp Name of the event to attach the listener to.
listener function Method to be called when the event is triggered.

audioTrack.off(evt, listener)
method

Removes a listener function from the event on the node.
When passed a regular expression as the event name, it will remove the listener from all events that match it.

See: on, once, trigger

Param Type Description
evt string | RegExp Name of the event to remove the listener from.
listener function Method to remove from the event.

audioTrack.trigger(evt)
method

Triggers an event of your choice.
When triggered, every listener attached to that event will be executed.
If you pass the optional arguments then those arguments will be passed to every listener upon execution.

See: on, once, off

Param Type Description
evt string | RegExp Name of the event to emit and execute listeners for.
[…args] * Optional arguments to be passed to each listener.

Events

“volumechange”
event

Triggered when the audio volume changes (i.e. the volume is set or the muted property is changed).

Param Type Description
audioTrack AudioTrack This AudioTrack instance.
Rate this page: X
Tell us more!