fadeOut
fadeOut(id: string, duration?: number, startVolume?: number, endVolume?: number, stopAfterFade?: boolean, skipDispatchEvent?: boolean): void;
Fade a playing sound's volume down over duration seconds. Optionally stop the sound automatically once the fade completes.
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | — | ID of the sound to fade out |
duration | number | 1 | Fade duration in seconds |
startVolume | number | current | Volume to start from |
endVolume | number | 0 | Volume to reach |
stopAfterFade | boolean | false | When true, stops the sound after the fade completes |
skipDispatchEvent | boolean | false | When true, suppresses the fade event |
tip
You can also trigger a fade-out automatically before a sound ends via PlayOptions.fadeOutBeforeEndDuration.
Example
await soundManager.loadSounds([{ id: 'tokyo-train', url: 'tokyo-train-melody.mp3' }]);
soundManager.play('tokyo-train', { loop: true });
// Fade out over 4 seconds, then stop
soundManager.fadeOut('tokyo-train', 4, undefined, undefined, true);
// Or just lower the volume without stopping
soundManager.fadeOut('tokyo-train', 2, undefined, 0.2);
⏱ Fade Duration3s
0.5s8s
Try it: Play the sound, then fade it out. Toggle
stopAfterFade to hear the difference between a full stop and just lowering the volume.