Skip to main content

AudioPlayer Node

The audio player node can load audio files and play them.

Number of inputs0
Number of outputs1

Configuration

audioFilePath (Optional)

Type: String

File path of audio file that will be loaded when the node is created.

startPosition (Optional)

Type: Double

The position in seconds where playback starts and where looping returns to. Defaults to 0.

endPosition (Optional)

Type: Double

The position in seconds where playback ends and where looping wraps around. Defaults to the duration of the loaded audio.

loopCrossfadeMs (Optional)

Type: Double

Length in milliseconds of the equal-power crossfade applied at the loop point. Defaults to 0, which loops with a hard splice. Clamped to at most 50 ms.

The fade overlaps the audio before startPosition, so the audible loop period stays exactly endPosition - startPosition. It therefore needs at least the fade length of audio before startPosition, and a loop region longer than the fade; when either is missing the node logs a warning and loops without a crossfade.

Only applies to loaded audio. Streaming playback started with the stream action ignores it.

This is a construction-time setting: it is not exposed as a property and cannot be changed with setValue.


Properties

Inherits properties from its parent, SingleBusAudioSourceNode.

isLoopingEnabled

Type: Bool

Indicates whether looping of the audio file is enabled.

position

Type: Double

The current position of the playback head in seconds.

duration (Read only)

Type: Double

The duration of the loaded audio in seconds. 0 is returned if no audio has been loaded.

startPosition

Type: Double

The position in seconds where playback starts and where looping returns to.

Values outside the loaded audio are clamped, and reading the property back returns the clamped value. The region is kept across load and stream calls, so it does not need to be set again for every file.

endPosition

Type: Double

The position in seconds where playback ends and where looping wraps around.

With looping enabled, playback returns to startPosition when this position is reached. The wrap is sample accurate.


Actions

Inherits actions from its parent, SingleBusAudioSourceNode.

play

Starts the audio playback.

Parameters

None.

Return Value

None.

pause

Pauses the audio playback.

Parameters

None.

Return Value

None.

stop

Stops the audio playback and resets the playback head to the beginning.

Parameters

None

Return Value

None.

load

Loads an audio file into memory.

Parameters

NameTypeDescription
audioFilePathStringThe path to the audio file to load.
codec (Optional)StringThe codec to use to decode the audio file. Codec will be automatically selected if this parameters is not provided.

Return Value

None.

stream

Opens an audio file for reading. The file will be streamed from disk while playing.

Parameters

NameTypeDescription
audioFilePathStringThe path to the audio file to load.
codec (Optional)StringThe codec to use to decode the audio file. Codec will be automatically selected if this parameters is not provided.

Return Value

None.


Events

Inherits events from its parent, SingleBusAudioSourceNode.

This object does not provide any events.