BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Audio Library Howler.js Has 2.0 Release to Make Some Noise about

Audio Library Howler.js Has 2.0 Release to Make Some Noise about

The JavaScript audio library Howler.js has been upgraded to version 2.0, with an update including "a long list of additions and improvements."

Howler.js author James Simpson, founder of game development studio Goldfire Studios, said the release represents a "full rewrite" of Howler and is now 100% compatible across both HTML5 and Web Audio. Simpson is quick to point out the release is thanks to the work of dozens of contributors.

In the blog post Howler.js v2.0 Released Simpson describes howler.js as a "modular library" saying that it allows for "a lean core that can be extended to add more advanced functionality, such as the wealth of tools available as part of the broader Web Audio API (spatial audio, filters, etc)."

"Howler.js is now modularised. The core represents the initial goal for howler.js," Simpson said, with the spatial plugin adding spatial and stereo support through the Web Audio API.

The biggest change in version 2.0, he says, addresses a significant pain point from the 1.x series. A confusion over the playback of multiple sounds was tackled with the introduction of a 3-layer solution.

The update represents a change in how developers should think about audio when using howler.js. Simpson says:

There is now the concept of global (Howler), group (Howl) and single sound (Sound). Each sound that is played gets its own Sound object that can be manipulated, giving much greater control over playback, whether using sprites or not. Howl method calls can then apply to one sound or all in the group
Howler (global) ->
        Howl (group) ->
               Sound (single)

Furthermore, new methods in howler.js' major upgrade include once to setup event listeners that will automatically remove themselves once fired, playing that will return true if the specified sound is currently playing, duration that will return the duration of the audio source, state that will return the loaded state of the Howl, and the new global unload method that unloads all active Howls and resets the AudioContext to clear memory.

The 2.0 release for Howler also brings welcome support for the playback of Dolby Audio and CAFF audio files, as well as the .webm extension in addition to .weba.

Also tackling a number of bugs, the many fixes in howler.js include improving the ext option, making it more useful for playing streams (SoundCloud is provided as an example). In addition, Howler.js 2.0 fixes a potential memory leak when using the unload method, and the library now also falls back to HTML5 Audio when loading an HTTP file on an HTTPS page.

Among the breaking changes in 2.0 is the play method no longer taking a callback and immediately returning the playback sound id. Simpson says this means you can no longer chain onto the play method, but says all others work the same:

// Get sound id for a specific playback.
var id = sound.play();

// Pause this playback.
sound.pause(id);

Also breaking is the deprecated fadeIn and fadeOut methods, that have been removed in favor of the single fade method:

// Fade in a sound.
sound.fade(0, 1, 1000);

// Fade out the sound once the previous fade has ended.
sound.once('fade', function(){
  sound.fade(1, 0, 1000);
});

The full changelog for howler.js 2.0 can be viewed here. Howler.js is released via an MIT licence, and is used by companies including Google, Disney, Lego and Mozilla, as well as NASA.

Rate this Article

Adoption
Style

BT