Skip to main content

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​

ParameterTypeDefaultDescription
idstringrequiredID 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 getGlobalVolume for that.
  • A mute does not change the value on a buffered sound. For a muted stream from loadStream you get 0.
  • For an id that is not loaded, the error is logged, stored for getLastError and dispatched as an error event.

See also​