Constructor
new SoundInstance(sound, volumeopt, rateopt, panopt, loopopt, pausedopt)
Create a sound instance
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sound | Sound | The sound object | ||
volume | number | <optional> | 1 | How much to scale volume by |
rate | number | <optional> | 1 | The playback rate to use |
pan | number | <optional> | 0 | How much to apply stereo panning |
loop | boolean | <optional> | false | Should the sound loop? |
paused | boolean | <optional> | false | Should the sound start paused? |
- Source
// Play a sound and get an instance for control
const jumpSound = new Sound([.5,.5,220]);
const instance = jumpSound.play();
// Control the individual instance
instance.setVolume(.5);
instance.pause();
instance.unpause();
instance.stop();
Members
gainNode
PropertiesType | Description |
---|---|
GainNode | Gain node for the sound |
- Source
loop
PropertiesType | Description |
---|---|
boolean | Should the sound loop |
- Source
pan
PropertiesType | Description |
---|---|
number | How much to apply stereo panning |
- Source
pausedTime
PropertiesType | Description |
---|---|
number | Timestamp for audio context when paused |
- Source
rate
PropertiesType | Description |
---|---|
number | The playback rate to use |
- Source
sound
PropertiesType | Description |
---|---|
Sound | The sound object |
- Source
source
PropertiesType | Description |
---|---|
AudioBufferSourceNode | Source node of the audio |
- Source
startTime
PropertiesType | Description |
---|---|
number | Timestamp for audio context when started |
- Source
volume
PropertiesType | Description |
---|---|
number | How much to scale volume by |
- Source
Methods
getCurrentTime() → {number}
Get the current playback time in seconds
- Source
- Current playback time
- Type:
- number
getDuration() → {number}
Get the total duration of this sound
- Source
- Total duration in seconds
- Type:
- number
getSource() → {AudioBufferSourceNode}
Get source of this sound instance
- Source
- Type:
- AudioBufferSourceNode
isPaused() → {boolean}
Check if this instance is paused and was not stopped
- Source
- True if paused
- Type:
- boolean
isPlaying() → {boolean}
Check if this instance is currently playing
- Source
- True if playing
- Type:
- boolean
pause()
Pause this sound instance
- Source
resume()
Unpauses this sound instance
- Source
setVolume(volume)
Set the volume of this sound instance
Name | Type | Description |
---|---|---|
volume | number |
- Source
start(offsetopt)
Start playing the sound instance from the offset time
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
offset | number | <optional> | 0 | Offset in seconds to start playback from |
- Source
stop()
Stop this sound instance and reset position to the start
- Source