Skip to main content

Howler

Added in 6.5.0

Howler from soundhub/howler is the global object of Howler.js: master volume and mute, and the audio context every Howl shares. On top of that it hands out the SoundHub underneath, and lets you configure it.

import { Howler } from 'soundhub/howler';

Members​

MemberReturnsWhat it does
Howler.volume()numberThe master volume, from 0 to 1.
Howler.volume(volume)HowlerSet the master volume, through setGlobalVolume.
Howler.mute(muted)HowlerMute or unmute everything, through muteAllSounds and unmuteAllSounds.
Howler.stop()HowlerStop every voice of every Howl.
Howler.unload()HowlerUnload every Howl and destroy the hub. The next Howl makes a new one.
Howler.codecs(extension)booleanWhether the browser plays a format such as 'mp3', 'ogg' or 'webm', through canPlay.
Howler.ctxAudioContextThe audio context, the same as getContext.
Howler.masterGainAudioNodeThe entry of the master chain, the same as getMasterInput.
Howler.hubSoundHubThe hub every Howl plays through.
Howler.configure(config)HowlerSet the SoundHubConfig of the hub, before it is made.

The type of the object is HowlerGlobal, exported from soundhub/howler.

Howler.hub​

Every Howl is a sound in this hub, under the id in howl.soundhubId. Use it for anything Howler has no method for:

import { Howl, Howler } from 'soundhub/howler';

const music = new Howl({ src: '/audio/music.mp3', loop: true });
const voice = new Howl({ src: '/audio/voice.mp3' });

Howler.hub.duck(music.soundhubId, { when: voice.soundhubId, amount: 0.3 });
Howler.hub.setMasterLimiter(true);

Howler.configure​

configure(config: SoundHubConfig): HowlerGlobal;

Call it before the first Howl. The hub is made once, by the first new Howl() or the first use of hub, ctx, masterGain, volume, mute or codecs, and configure() after that throws an error.

import { Howl, Howler } from 'soundhub/howler';

Howler.configure({ masterLimiter: true, autoMuteOnHidden: true });

const sfx = new Howl({ src: '/audio/sfx.mp3' });

Without a config, the hub starts with autoMuteOnHidden: false and trackProgress: false, since Howler does neither. The rest is the soundhub default. After Howler.unload() the next Howl makes a new hub with the config you set.

Good to know​

  • Howler.mute(true) mutes the master bus, so a Howl that starts while it is muted stays silent until Howler.mute(false).
  • Howler.mute() has no getter form, and the hub has no getter for the master mute either. Keep the state yourself, or listen for mute_global and unmute_global on Howler.hub.
  • Howler.autoSuspend, autoUnlock, html5PoolSize, usingWebAudio, noAudio, pos and orientation are not there. autoUnlock and autoSuspend are hub config, so pass them to configure().

See also​