WebAudioPlayer
Defined in: src/webaudio/WebAudioPlayer.ts:22
Audio player built around the Web Audio API.
Capable of playing PCM streams, with volume adjustment and an optional equalizer. Only available in browser contexts.
Constructors
new WebAudioPlayer()
new WebAudioPlayer():
WebAudioPlayer
Defined in: src/webaudio/WebAudioPlayer.ts:68
Returns
Accessors
volume
Get Signature
get volume():
number
Defined in: src/webaudio/WebAudioPlayer.ts:79
Returns
number
Set Signature
set volume(
value
):void
Defined in: src/webaudio/WebAudioPlayer.ts:75
The audio output volume. Range is 0 to 1.
Parameters
Parameter | Type |
---|---|
value | number |
Returns
void
loop
Get Signature
get loop():
boolean
Defined in: src/webaudio/WebAudioPlayer.ts:92
Returns
boolean
Set Signature
set loop(
value
):void
Defined in: src/webaudio/WebAudioPlayer.ts:86
Whether the audio should loop after it has ended
Parameters
Parameter | Type |
---|---|
value | boolean |
Returns
void
Properties
ctx
ctx:
AudioContext
Defined in: src/webaudio/WebAudioPlayer.ts:27
Audio context, see AudioContext.
sampleRate
sampleRate:
number
Defined in: src/webaudio/WebAudioPlayer.ts:31
Audio sample rate.
useEq
useEq:
boolean
=false
Defined in: src/webaudio/WebAudioPlayer.ts:35
Whether the audio is being run through an equalizer or not.
useAnalyser
useAnalyser:
boolean
=false
Defined in: src/webaudio/WebAudioPlayer.ts:39
Whether to connect the output to an audio analyser (see analyser).
eqSettings
eqSettings: [
number
,number
][]
Defined in: src/webaudio/WebAudioPlayer.ts:43
Default equalizer settings. Credit to Sudomemo for these.
analyser
analyser:
AnalyserNode
Defined in: src/webaudio/WebAudioPlayer.ts:57
If enabled, provides audio analysis for visualization etc - https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Visualizations_with_Web_Audio_API
Methods
setBuffer()
setBuffer(
inputBuffer
,sampleRate
):void
Defined in: src/webaudio/WebAudioPlayer.ts:107
Set the audio buffer to play
Parameters
Parameter | Type | Description |
---|---|---|
inputBuffer | PcmAudioBuffer | |
sampleRate | number | For best results, this should be a multiple of 16364 |
Returns
void
setAnalyserEnabled()
setAnalyserEnabled(
on
):void
Defined in: src/webaudio/WebAudioPlayer.ts:179
Parameters
Parameter | Type |
---|---|
on | boolean |
Returns
void
setVolume()
setVolume(
value
):void
Defined in: src/webaudio/WebAudioPlayer.ts:188
Sets the audio volume level
Parameters
Parameter | Type | Description |
---|---|---|
value | number | range is 0 to 1 |
Returns
void
playFrom()
playFrom(
currentTime
):void
Defined in: src/webaudio/WebAudioPlayer.ts:203
Begin playback from a specific point
Note that the WebAudioPlayer doesn’t keep track of audio playback itself. We rely on the Player API for that.
Parameters
Parameter | Type | Description |
---|---|---|
currentTime | number | initial playback position, in seconds |
Returns
void
stop()
stop():
void
Defined in: src/webaudio/WebAudioPlayer.ts:214
Stops the audio playback
Returns
void
getCurrentTime()
getCurrentTime():
number
Defined in: src/webaudio/WebAudioPlayer.ts:222
Get the current playback time, in seconds
Returns
number
destroy()
destroy():
Promise
<void
>
Defined in: src/webaudio/WebAudioPlayer.ts:229
Frees any resources used by this canvas instance
Returns
Promise
<void
>