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
| Member | Returns | What it does |
|---|---|---|
Howler.volume() | number | The master volume, from 0 to 1. |
Howler.volume(volume) | Howler | Set the master volume, through setGlobalVolume. |
Howler.mute(muted) | Howler | Mute or unmute everything, through muteAllSounds and unmuteAllSounds. |
Howler.stop() | Howler | Stop every voice of every Howl. |
Howler.unload() | Howler | Unload every Howl and destroy the hub. The next Howl makes a new one. |
Howler.codecs(extension) | boolean | Whether the browser plays a format such as 'mp3', 'ogg' or 'webm', through canPlay. |
Howler.ctx | AudioContext | The audio context, the same as getContext. |
Howler.masterGain | AudioNode | The entry of the master chain, the same as getMasterInput. |
Howler.hub | SoundHub | The hub every Howl plays through. |
Howler.configure(config) | Howler | Set 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 untilHowler.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 formute_globalandunmute_globalonHowler.hub.Howler.autoSuspend,autoUnlock,html5PoolSize,usingWebAudio,noAudio,posandorientationare not there.autoUnlockandautoSuspendare hub config, so pass them toconfigure().
See also
Howl: the class.- Migrating from Howler.js: the overview.