Create a new SoundInstance instance.
The sound manager.
The sound to play.
Options for the instance.
Optionalduration?: numberThe total time after the startTime in seconds when playback will stop or restart if loop is true. Defaults to 0.
Optionalloop?: booleanWhether the sound should loop when it reaches the end or not. Defaults to false.
OptionalonEnd?: FunctionFunction called when the instance ends.
OptionalonPause?: FunctionFunction called when the instance is paused.
OptionalonPlay?: FunctionFunction called when the instance starts playing.
OptionalonResume?: FunctionFunction called when the instance is resumed.
OptionalonStop?: FunctionFunction called when the instance is stopped.
Optionalpitch?: numberThe relative pitch. Defaults to 1 (plays at normal pitch).
OptionalstartTime?: numberThe time from which the playback will start in seconds. Default is 0 to start at the beginning. Defaults to 0.
Optionalvolume?: numberThe playback volume, between 0 and 1. Defaults to 1.
Gets the source that plays the sound resource. If the Web Audio API is not supported the type of source is Audio. Source is only available after calling play.
Gets the current time of the sound that is playing.
Sets the current time of the sound that is playing. If the value provided is bigger than the duration of the instance it will wrap from the beginning.
Gets the duration of the sound that the instance will play starting from startTime.
Sets the duration of the sound that the instance will play starting from startTime.
Gets whether the instance is currently paused.
Gets whether the instance is currently playing.
Gets whether the instance is currently stopped.
Gets whether the instance is currently suspended because the window is not focused.
Gets whether the instance will restart when it finishes playing.
Sets whether the instance will restart when it finishes playing.
Gets the pitch modifier to play the sound with.
Sets the pitch modifier to play the sound with. Must be larger than 0.01.
Gets the sound resource that the instance will play.
Gets the start time from which the sound will start playing.
Sets the start time from which the sound will start playing.
Gets the volume modifier to play the sound with. In range 0-1.
Sets the volume modifier to play the sound with. In range 0-1.
Clears any external nodes set by SoundInstance#setExternalNodes.
Fire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optionalarg1: anyFirst argument that is passed to the event handler.
Optionalarg2: anySecond argument that is passed to the event handler.
Optionalarg3: anyThird argument that is passed to the event handler.
Optionalarg4: anyFourth argument that is passed to the event handler.
Optionalarg5: anyFifth argument that is passed to the event handler.
Optionalarg6: anySixth argument that is passed to the event handler.
Optionalarg7: anySeventh argument that is passed to the event handler.
Optionalarg8: anyEighth argument that is passed to the event handler.
Self for chaining.
Gets any external nodes set by SoundInstance#setExternalNodes.
Returns an array that contains the two nodes set by SoundInstance#setExternalNodes.
Test if there are any handlers bound to an event name.
The name of the event to test.
True if the object has handlers bound to the specified event name.
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optionalname: stringName of the event to unbind.
Optionalcallback: HandleEventCallbackFunction to be unbound.
Optionalscope: anyScope that was used as the this when the event is fired.
Self for chaining.
const handler = () => {};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optionalscope: any = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optionalscope: any = ...Object to use as 'this' when the event is fired, defaults to current this.
Pauses playback of sound. Call resume() to resume playback from the same position.
Returns true if the sound was paused.
Attempt to begin playback the sound. If the AudioContext is suspended, the audio will only start once it's resumed. If the sound is already playing, this will restart the sound.
True if the sound was started immediately.
Resumes playback of the sound. Playback resumes at the point that the audio was paused.
Returns true if the sound was resumed.
Connects external Web Audio API nodes. You need to pass the first node of the node graph that you created externally and the last node of that graph. The first node will be connected to the audio source and the last node will be connected to the destination of the AudioContext (e.g. speakers). Requires Web Audio API support.
Stops playback of sound. Calling play() again will restart playback from the beginning of the sound.
Returns true if the sound was stopped.
StaticEVENT_Fired when the sound currently played by the instance ends.
StaticEVENT_Fired when the instance is paused.
StaticEVENT_Fired when the instance starts playing its source.
StaticEVENT_Fired when the instance is resumed.
StaticEVENT_Fired when the instance is stopped.
A SoundInstance plays a Sound.