Constructor
new AudioItem(sourceopt, configopt)
Creates an instance of AudioItem.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
source |
string | AudioBuffer | null |
<optional> |
null | The URL of the audio file to load, or decoded audio data. |
config |
Object |
<optional> |
{} | Configuration for the audio item. |
- Source:
Classes
Members
currentTime
Gets the current playback position in seconds.
- Source:
duration
Gets the audio duration in seconds.
- Source:
loop
Gets the loop property.
- Source:
pitch
Gets the pitch value.
- Source:
seek
Gets the seek position in seconds.
- Source:
Methods
connect(audioMixer)
Connects the current instance to the provided audio mixer.
If already connected to a different audio mixer, it will first disconnect from the current one.
Parameters:
| Name | Type | Description |
|---|---|---|
audioMixer |
Object | The audio mixer to connect to. |
- Source:
disconnect()
Disconnects the current instance from the audio mixer.
If an audio mixer is connected, it stops the audio and disconnects the instance from the mixer.
- Source:
(async) load(source) → {Promise.<void>}
Asynchronously loads audio data from the provided URL, or uses already decoded audio data.
One AudioBuffer can be shared by several items, so the same sound can overlap itself
without fetching or decoding it again.
Parameters:
| Name | Type | Description |
|---|---|---|
source |
string | AudioBuffer | The URL of the audio resource to load, or decoded audio data. |
- Source:
Returns:
A promise that resolves when the audio data is loaded.
- Type
- Promise.<void>
pause()
Pauses the audio playback and stores the current seek position.
- Source:
play(fromopt)
Starts playing the audio from the current seek position or a specified time.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
from |
number |
<optional> |
this.seek | The time in seconds from which to start playing the audio. |
- Source:
stop()
Stops the audio playback and resets the seek position.
- Source:
unload()
Unloads the current instance by disconnecting and clearing the buffer.
- Source: