setSoundVolume
setSoundVolume(id: string, volume: number, skipDispatchEvent?: boolean): void;
Set the volume of a specific sound. The volume is applied immediately, even while the sound is playing. Use setGlobalVolume to adjust all sounds at once.
| Parameter | Type | Description |
|---|---|---|
id | string | ID of the sound to adjust |
volume | number | Volume level between 0 (silent) and 1 (full) |
skipDispatchEvent | boolean | When true, suppresses the volume change event |
Example
await soundManager.loadSounds([{ id: 'tokyo-train', url: 'tokyo-train-melody.mp3' }]);
soundManager.play('tokyo-train', { loop: true });
// Halve the volume
soundManager.setSoundVolume('tokyo-train', 0.5);
// Silence the sound without stopping it
soundManager.setSoundVolume('tokyo-train', 0);
🔉 Volume60%
0%100%
Try it: Play the sound and drag the slider — the volume updates in real time while the sound is playing.