Creates an instance of the Playback class.
The Sound instance that the Playback is associated with.
The audio source node.
The gain node for controlling volume.
Throws an error if an invalid pan type is provided.
Private _offsetPrivate _playbackPrivate _startPrivate _statePrivate Optional bufferPrivate contextOptional gainThe Sound instance that the Playback is associated with.
Optional pannerOptional sourceGets the duration of the audio in seconds.
The duration of the audio or NaN if the duration is unknown.
Throws an error if the sound has been cleaned up.
Gets the output node of this playback's audio graph. This is the final node in the internal chain before connection to destination. Use this to manually wire the playback into custom audio graphs.
The gain node that serves as the output of this playback.
Throws an error if the playback has been cleaned up.
// Manual routing through custom effects
const playback = sound.play()[0];
playback.disconnect(); // Disconnect from default destination
playback.connect(reverbNode).connect(context.destination);
Gets the current playback rate of the audio.
The current playback rate.
Sets the playback rate of the audio.
The playback rate to set.
Throws an error if the sound has been cleaned up or if the source type is unsupported.
Gets the position of the audio source in 3D space (HRTF panning only).
The [x, y, z] coordinates of the audio source.
Throws an error if the sound has been cleaned up or if HRTF panning is not used.
Sets the position of the audio source in 3D space (HRTF panning only).
The [x, y, z] coordinates of the audio source.
Throws an error if the sound has been cleaned up or if HRTF panning is not used.
Sets whether the audio source should loop.
Whether the audio should loop.
Throws an error if the sound has been cleaned up.
Gets the stereo panning value.
The current stereo pan value, or null if stereo panning is not applicable.
Throws an error if stereo panning is not available or if the sound has been cleaned up.
Sets the stereo panning value.
The stereo pan value to set, between -1 (left) and 1 (right).
Throws an error if stereo panning is not available, if the sound has been cleaned up, or if the value is out of bounds.
Gets the 3D audio options if HRTF panning is used.
The current 3D audio options.
Throws an error if the sound has been cleaned up or if HRTF panning is not used.
Sets the 3D audio options for HRTF panning.
The 3D audio options to set.
Throws an error if the sound has been cleaned up or if HRTF panning is not used.
Gets the current volume of the audio.
The current volume.
Throws an error if the sound has been cleaned up.
Sets the volume of the audio.
The volume to set.
Throws an error if the sound has been cleaned up.
Private assertCreates a clone of the current Playback instance with optional overrides for certain properties. This method allows for the creation of a new Playback instance that shares the same audio context and source node but can have different settings such as loop count or pan type.
An object containing properties to override in the cloned instance.
A new Playback instance cloned from the current one with the specified overrides applied.
Throws an error if the sound has been cleaned up.
Connects this playback's output to an AudioNode or AudioParam. Follows the Web Audio API connection pattern.
The node or param to connect to.
The destination node (for chaining).
Throws an error if the playback has been cleaned up.
// Chain multiple effects
playback.connect(delay).connect(reverb).connect(context.destination);
Disconnects this playback's output from a specific destination or from all destinations.
Optional destination: AudioNode | AudioParamOptional specific destination to disconnect from. If omitted, disconnects from all destinations.
Throws an error if the playback has been cleaned up.
// Disconnect from all
playback.disconnect();
// Disconnect from specific node
playback.disconnect(reverbNode);
Sets or gets the loop count for the audio.
Optional loopCount: LoopCountThe number of times the audio should loop. 'infinite' for endless looping.
The loop count if no parameter is provided.
Throws an error if the sound has been cleaned up or if the source type is unsupported.
Private recreatePrivate refreshPrivate setup
The base interface for any sound-producing entity, including individual sounds, groups, and playbacks. BaseSound