Class: AudioSource
AudioSource is a component for storing information around audio and how it should be played.
Hierarchy
-
↳ AudioSource
Table of contents
Constructors
Properties
Methods
Constructors
constructor
+ new AudioSource(audio
: string, options?
: IAudioOptions, playCount?
: number): AudioSource
Parameters:
Name | Type | Default value |
---|---|---|
audio |
string | - |
options |
IAudioOptions | - |
playCount |
number | 0 |
Returns: AudioSource
Inherited from: Component
Properties
audio
• audio: string
The name of the audio asset to play.
audioProcessor
• Optional
audioProcessor: undefined | (base
: AudioBufferSourceNode, context
: AudioContext) => AudioNode
Audio processing function, during audio playback this function will be called and allows injection of filters/customisation. This uses the Web Audio API. The node returned should be the last node in the node chain. https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API
key
• key: string
loop
• loop: number
If the audio should loop, equal to the number of loops it should complete, or -1 for an infinite amount of loops. E.g. a value of 3 would result in 1 initial play and 3 looped plays.
playCount
• playCount: number
Internal variable used to track how many times the audio source has been played, used to determine if it should continue looping.
playbackRate
• playbackRate: number
The playback rate for the audio as a decimal proportion of the original sampling rate. A value of 1.0 is the audio at normal speed, 0.5 is half speed, 2.0 is double speed.
playing
• playing: boolean
If the audio is playing or not, true = playing, false = not playing.
volume
• volume: number
The volume of the audio, between 0 and 1
KEY
▪ Readonly
Static
KEY: audio_source= "audio_source"
Key of the audio source component.
MESSAGE_ADD
▪ Readonly
Static
MESSAGE_ADD: component_add= "component_add"
Inherited from: Component.MESSAGE_ADD
MESSAGE_REMOVE
▪ Readonly
Static
MESSAGE_REMOVE: component_remove= "component_remove"
Inherited from: Component.MESSAGE_REMOVE
Methods
Free
▸ Free(): void
Returns: void
Inherited from: Component
Play
▸ Play(): void
Plays the audio, resets the play counter; will loop again for the number of times specified.
Returns: void
Stop
▸ Stop(): void
Stops the audio, when it is replayed it will play from the start.
Returns: void