getVolume
Read the volume of one sound or stream. It returns exactly what getSoundVolume returns, so use whichever name reads better in your code.
getVolume(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.play('music', { volume: 0.7 });
soundHub.getVolume('music'); // 0.7
Good to know
- This is the volume of one sound. It is not the master volume; use
getGlobalVolumefor that. - A
mutedoes not change the value on a buffered sound. For a muted stream fromloadStreamyou get0. - For an id that is not loaded, the error is logged, stored for
getLastErrorand dispatched as anerrorevent.
See also
getSoundVolume: the same value.setSoundVolume: set the volume of a sound.getGlobalVolume: the master volume.