getSoundVolume
Read the volume of one sound, for example to set a per-sound slider.
getSoundVolume(id: string): number;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | required | ID of the sound or stream. |
Returns
number: the sound's volume from 0 to 1. For an id that is not loaded you get 0.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.setSoundVolume('music', 0.4);
soundHub.getSoundVolume('music'); // 0.4
soundHub.mute('music');
soundHub.getSoundVolume('music'); // still 0.4
Good to know
- A
mutedoes not change the value: you get the volume the sound comes back to. The same goes formuteAllSoundsand the master volume, which are not included. - During
fadeInorfadeOutthe value follows the fade. - For a stream from
loadStreamit returns the stream's volume, which is0while the stream is muted. - For an id that is not loaded, the error is logged, stored for
getLastErrorand dispatched as anerrorevent.
See also
setSoundVolume: set the volume of a sound.getVolume: the same value under another name.getGlobalVolume: the master volume.