AudioFile
Summary
AudioPlayer that handles loading and playback of audio files.Remarks
Like AudioPlayer this class acts as an AudioNode
which can be used as an input to
AudioObject instances.Constructor
Constructs an AudioFile instance.
Signature
new AudioFile(context: BaseAudioContext)
Name | Type | Description |
---|---|---|
context | BaseAudioContext | AudioContext to use |
Methods
isPlaying
Returns true if the player is currently playing, false otherwise.
Signature
isPlaying()
Returns
boolean
load
Loads audio data from a file or URL. Can be configured to start playback when loading
is complete.
Signature
load(path: string | URL, shouldPlayOnLoad?: boolean)
Name | Type | Description |
---|---|---|
path | string | URL | |
shouldPlayOnLoad optional | boolean |
Returns
Promise
<void
>💡
If playback is already running and load is called again with shouldPlayOnLoad = true,
then playback of the previous buffer stops and the new buffer is played back immediately.
pause
Pauses playback. Can be resumed by calling
play
.Signature
pause()
Returns
void
play
Starts playback.
Signature
play()
Returns
void
setBuffer
Sets the audio buffer to be played back from.
Signature
setBuffer(buffer: AudioBuffer)
Name | Type | Description |
---|---|---|
buffer | AudioBuffer | new audio buffer |
Returns
void
setLoop
Sets whether or not the audio should be looped.
Signature
setLoop(shouldLoop: boolean)
Name | Type | Description |
---|---|---|
shouldLoop | boolean | loop status to set |
Returns
void
stop
Stops playback. The next
play
call will playback the buffer from the beginning.Signature
stop()
Returns
void
togglePlayback
Starts playback if not playing currently, stops playback otherwise.
Signature
togglePlayback()
Returns
void