Create a new SoundInstance instance.
The sound manager.
The sound to play.
Options for the instance.
The total time after the startTime in seconds when playback will stop or restart if loop is true. Defaults to 0.
Whether the sound should loop when it reaches the end or not. Defaults to false.
Function called when the instance ends.
Function called when the instance is paused.
Function called when the instance starts playing.
Function called when the instance is resumed.
Function called when the instance is stopped.
The relative pitch. Defaults to 1 (plays at normal pitch).
The time from which the playback will start in seconds. Default is 0 to start at the beginning. Defaults to 0.
The 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 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.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: 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.
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.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const handler = function () {
};
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.
Optional
scope: object = ...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.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
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.
Static
EVENT_Fired when the sound currently played by the instance ends.
Static
EVENT_Fired when the instance is paused.
Static
EVENT_Fired when the instance starts playing its source.
Static
EVENT_Fired when the instance is resumed.
Static
EVENT_Fired when the instance is stopped.
A SoundInstance plays a Sound.