- Version
- 1.0.0
- License
- MIT
- Source
- AudioChain.js, line 11
Constructor
new AudioChain(player, parent, optionsopt)
Creates an instance of the AudioChain component.
Members
private #player :Player
Reference to the main player instance.
- Type
- Player
- Source
- AudioChain.js, line 17
private #subscriptions :Array<number>
Holds tokens of subscriptions to player events, for later unsubscribe.
- Type
- Array<number>
- Source
- AudioChain.js, line 23
private #apiKey :symbol
Secret key only known to the player instance and initialized components. Used to be able to restrict access to API methods in conjunction with secure mode.
- Type
- symbol
- Source
- AudioChain.js, line 30
private #audioContext :AudioContext
The Web Audio API context.
- Type
- AudioContext
- Source
- AudioChain.js, line 36
private #masterGain :AudioNode
The Master Gain Node. All nodes will eventually connect to masterGain -> speakers.
- Type
- AudioNode
- Source
- AudioChain.js, line 42
private #nodes :Array<{input: AudioNode, output: (AudioNode|null), order: number}>
List of registered audio nodes.
- Type
- Array<{input: AudioNode, output: (AudioNode|null), order: number}>
- Source
- AudioChain.js, line 48
private #mediaSource :MediaElementAudioSourceNode|null
The MediaElementSourceNode connected to the video element. Will be set in connectVideo().
- Type
- MediaElementAudioSourceNode | null
- Source
- AudioChain.js, line 54
private #suspendDelayId :number
Timeout id delaying suspending.
- Type
- number
- Source
- AudioChain.js, line 60
Methods
private #getContext(apiKey) → AudioContext
Provides the audio context of this component.
| Name | Type | Description |
|---|---|---|
apiKey |
symbol |
Token needed to grant access in secure mode. |
- Returns
-
The current AudioContext.
- Type AudioContext
- Throws
-
If safe mode access was denied.
Type Error - Source
- AudioChain.js, line 102
private #addNode(input, output, orderopt, apiKey)
Inserts an audio node into the internal processing chain. This method expects the input and output (or null if no output is defined, as with analysers)
of the processing chain to be inserted, and optionally an order value which determines when the inserted chain will be executed.
| Name | Type | Attributes | Description |
|---|---|---|---|
input |
AudioNode |
Input node receiving audio. |
|
output |
AudioNode | null |
Output node passing audio forward (null if not chaining). |
|
order |
number | optional |
Sorting index for node processing order. |
apiKey |
symbol |
Token needed to grant access in secure mode. |
- Throws
-
If safe mode access was denied.
Type Error - Source
- AudioChain.js, line 121
private #removeNode(input, output, apiKey)
Removes a previously added audio node from the processing chain. This method expects the input and outputs of the processing chain to be removed from the 'master chain'.
| Name | Type | Description |
|---|---|---|
input |
AudioNode |
Input node to remove. |
output |
AudioNode | null |
Output node to remove. |
apiKey |
symbol |
Token needed to grant access in secure mode. |
- Throws
-
If safe mode access was denied.
Type Error - Source
- AudioChain.js, line 142
private #connectVideo()
Connects the MediaElementAudioSourceNode to the Web Audio graph. Ensures that only one instance of mediaSource exists.
- Listens
- media/ready
- Source
- AudioChain.js, line 166
private #disconnectVideo()
Disconnects the MediaElementAudioSourceNode.
- Listens
- data/ready
- Source
- AudioChain.js, line 180
private #suspendAudio()
Suspends the audio context with a delay after pausing.
- Listens
- media/pause
- Source
- AudioChain.js, line 192
private #resumeAudio()
Resumes the audio context immediately when playback starts.
- Listens
- media/play
- Source
- AudioChain.js, line 203
private #connectAudio()
Builds the audio processing chain and connects nodes in the correct order.
- Source
- AudioChain.js, line 212
private #disconnectAudio()
Disconnects all audio nodes and resets the processing chain.
- Source
- AudioChain.js, line 237
destroy()
Completely tears down the audio system. Unsubscribes from all events, removes nodes, and closes the audio context.
- Source
- AudioChain.js, line 255