@fogrexon/glyph-arena-audio
Web Audio playback helper. See also package README.
Exports
Generated from the package's source when the docs are built — do not edit this table by hand.
| Name | Kind |
|---|---|
Audio | type |
CreateAudioOptions | type |
PlayHandle | type |
PlayOptions | type |
createAudio | function |
createAudio(options?)
const audio = createAudio({ context? });
const buffer = await audio.decode(bytes);
const handle = audio.play(buffer, { gain?, loop? });
audio.stop(handle);
await audio.resume();
audio.dispose();
Options
context?— existingAudioContext. When omitted, a new context is created and closed ondispose.
Methods
decode(bytes)— decodeArrayBuffertoAudioBufferviacontext.decodeAudioData.play(buffer, options?)— start playback. Returns an opaquePlayHandle(number). Does not callresumeautomatically.stop(handle)— stop active playback. Unknown or already-ended handles are no-ops.resume()— callcontext.resume().dispose()— reject pending decodes, stop all playback, and close an owned context. Borrowed contexts are not closed.
PlayOptions
| Field | Description |
|---|---|
gain? | volume multiplier, clamped to 0..1. Default 1. |
loop? | loop playback. Default false. |
After dispose()
decodeandresumereject with"Audio disposed".playreturns a handle without starting sound.- In-flight decodes reject when dispose runs.
Suspended context
play while the context is suspended still creates sources and returns a handle. Call resume() to unpause the context.