fadeIn
fadeIn(id: string, duration: number, startVolume?: number, endVolume?: number, skipDispatchEvent?: boolean): void;
Fade a playing sound's volume from startVolume to endVolume over duration seconds. Use this to smoothly introduce a sound that is already playing.
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | — | ID of the sound to fade in |
duration | number | — | Fade duration in seconds |
startVolume | number | 0 | Volume to start from |
endVolume | number | 1 | Volume to reach |
skipDispatchEvent | boolean | false | When true, suppresses the fade event |
tip
You can also trigger a fade-in directly from play() via PlayOptions.fadeInDuration — no need to call fadeIn separately.
Example
await soundManager.loadSounds([{ id: 'tokyo-train', url: 'tokyo-train-melody.mp3' }]);
// Start silent
soundManager.play('tokyo-train', { volume: 0, loop: true });
// Fade from 0 → 1 over 3 seconds
soundManager.fadeIn('tokyo-train', 3);
// Or fade from 0.2 → 0.8 over 2 seconds
soundManager.fadeIn('tokyo-train', 2, 0.2, 0.8);
⏱ Fade Duration3s
0.5s8s
Try it: Adjust the duration and click Fade In to hear the sound gradually rise to full volume.