fadeGlobalOut
Lower the master volume over a number of seconds, so the whole mix fades out. Use it at the end of a scene or before a page change.
fadeGlobalOut(duration?: number, startVolume?: number, endVolume?: number): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
duration | number | fadeOutDuration from the config (0.5) | Length of the fade in seconds. 0 or less does nothing. |
startVolume | number | current master volume | Master volume to start from. |
endVolume | number | 0 | Master volume to end at. |
Returns
Nothing.
Example
import { SoundHub, SoundEventsEnum } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.play('music', { loop: true });
// Stop everything once the fade has finished
soundHub.once(SoundEventsEnum.FADE_MASTER_OUT_COMPLETED, () => {
soundHub.stopAllSounds();
});
soundHub.fadeGlobalOut(3);
Try it
Fade the master volume
IdleDirection
Master gain1.00
The fade runs on the master gain, so every sound on the page follows it.
Code
Your clicks show up here as soundhub calls
Good to know
- The fade does not stop any sound. They keep playing at master volume
0until you stop them. - A fade that ends at
0counts as a global mute. The master stays silent for sounds you play later, until you callfadeGlobalIn,unmuteAllSoundsortoggleGlobalMute. All three go back to the volume the fade started from. - A running
fadeGlobalInorfadeGlobalOutis replaced. - Every step dispatches
master_volume_changed, and the end dispatchesSoundEventsEnum.FADE_MASTER_OUT_COMPLETED('fade_master_out_completed').
See also
fadeGlobalIn: bring the mix back.fadeOut: fade one sound out.muteAllSounds: silence the mix at once.