AudioSystem
Extends:
System used to manage audio.
Example:
const system = new AudioSystem();
Static Method Summary
Static Public Methods | ||
public static |
createAudioContext(): * |
Constructor Summary
Public Constructor | ||
public |
Constructor. |
Method Summary
Public Methods | ||
public |
dispose() Destructor (dispose internal resources). |
|
public |
Gets music instance. |
|
public |
Gets given sound instance. |
|
public |
Tells if given music is registered. |
|
public |
Tells if there is registered given sound. |
|
public |
Play given music. |
|
public |
Play given sound. |
|
public |
registerMusic(id: string, audio: HTMLAudioElement) Register new music. |
|
public |
registerSound(id: string, data: ArrayBuffer | AudioBuffer) Register new sound. |
|
public |
unregisterMusic(id: string) Unregister existing music. |
|
public |
unregisterSound(id: string) Unregister existing sound. |
|
public |
whenSoundIsReady(id: string): Promise Produces promise that resolves when sound is decoded into memory (decoding is done asynchronously). |
Inherited Summary
From class System | ||
public static get |
|
|
public static get |
systems: * |
|
public static |
dispose() Dispose and remove all registered systems. |
|
public static |
Returns system instance of given type name. |
|
public static |
Register new system instance under given name. |
|
public static |
unregister(typename: string): System Unregister given system. |
|
public |
dispose() Destructor (disposes all internal resources). |
|
public |
Event called after system gets registered. |
|
public |
Event called before system gets unregistered. |
Static Public Methods
Public Constructors
Public Members
public get context: AudioContext source
Public Methods
public dispose() source
Destructor (dispose internal resources).
Override:
System#disposeExample:
system.dispose();
system = null;
public getMusic(id: string): HTMLAudioElement | null source
Gets music instance.
Params:
Name | Type | Attribute | Description |
id | string | Music id. |
public getSound(id: string): AudioBufferSourceNode | null source
Gets given sound instance.
Params:
Name | Type | Attribute | Description |
id | string | Sound id. |
public hasMusic(id: string): boolean source
Tells if given music is registered.
Params:
Name | Type | Attribute | Description |
id | string | Music id. |
public hasSound(id: string): boolean source
Tells if there is registered given sound.
Params:
Name | Type | Attribute | Description |
id | string | Sound id. |
public playMusic(id: string): HTMLAudioElement source
Play given music. Mostly you will be able to play only one music at the same time.
Params:
Name | Type | Attribute | Description |
id | string | Music id. |
Return:
HTMLAudioElement | Music instance. |
public playSound(id: string, autoDestination: boolean): AudioBufferSourceNode source
Play given sound.
Return:
AudioBufferSourceNode | Sound audio buffer source node. |
public registerMusic(id: string, audio: HTMLAudioElement) source
Register new music.
Params:
Name | Type | Attribute | Description |
id | string | Music id. |
|
audio | HTMLAudioElement | HTML audio element. |
Example:
system.registerMusic('ambient', document.getElementById('ambient'));
public registerSound(id: string, data: ArrayBuffer | AudioBuffer) source
Register new sound.
Params:
Name | Type | Attribute | Description |
id | string | Sound id. |
|
data | ArrayBuffer | AudioBuffer | Sound data. |
public unregisterMusic(id: string) source
Unregister existing music.
Params:
Name | Type | Attribute | Description |
id | string | Music id. |
public unregisterSound(id: string) source
Unregister existing sound.
Params:
Name | Type | Attribute | Description |
id | string | Sound id. |