Skip to main content

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.

ParameterTypeDefaultDescription
idstringID of the sound to fade out
durationnumber1Fade duration in seconds
startVolumenumbercurrentVolume to start from
endVolumenumber0Volume to reach
stopAfterFadebooleanfalseWhen true, stops the sound after the fade completes
skipDispatchEventbooleanfalseWhen 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.