Skip to content

EZ Web Audio / setGlobalVolume

Function: setGlobalVolume()

setGlobalVolume(value): void

Defined in: packages/core/src/index.ts:272

Set the global volume applied to every sound routed through the shared master bus (R2#7). This is sugar over setMasterDestination: the first call lazily creates a managed GainNode wired to the hardware destination and installs it as the master destination, so instances created afterward pick it up automatically.

Only instances created AFTER the first setGlobalVolume()/muteAll() call route through the managed bus — existing instances keep their prior routing (move one with instance.setDestination(...) if needed). If you already installed your own bus via setMasterDestination (e.g. a limiter), call setGlobalVolume()/muteAll() first so your own call wins, or chain your node in front of the managed gain yourself.

Parameters

value

number

Volume from 0 (silent) to 1 (full). Throws a ValidationError for negative values, warns on the console above 1 — same rule as BaseSound.changeGainTo().

Returns

void

Example

typescript
import { createSound, setGlobalVolume } from 'ez-web-audio'

setGlobalVolume(0.5) // app-wide volume knob, set once at startup

const music = await createSound('theme.mp3')
music.play() // plays at half the master volume