howler.js Audio Library

2.2.4 · active · verified Sun Apr 19

howler.js is a robust JavaScript audio library designed for modern web applications, abstracting away the complexities of the Web Audio API and falling back seamlessly to HTML5 Audio when necessary. Currently stable at version 2.2.4, it sees regular maintenance releases addressing browser-specific quirks and improving reliability, such as fixes for Opera versions 100+ and Chrome for iOS. Key differentiators include its single, intuitive API, comprehensive cross-browser compatibility across desktop and mobile, support for audio sprites, 3D spatial audio, and an automatic HTML5 audio node pooling system to overcome common browser autoplay restrictions. It's a dependency-free, lightweight solution, offering full control over playback features like fading, rate, seek, and volume, suitable for a wide range of audio needs from simple sound effects to complex interactive audio experiences. It prioritizes performance with automatic caching and is modular, weighing in at just 7kb gzipped.

Common errors

Warnings

Install

Imports

Quickstart

Initializes and plays background music and a sound effect, demonstrating global mute/unmute functionality and basic playback options.

import { Howl, Howler } from 'howler';

// Initialize a Howl instance for a background music loop
const bgMusic = new Howl({
  src: ['/assets/music.mp3', '/assets/music.webm'],
  loop: true,
  volume: 0.5
});

// Initialize a Howl for a sound effect
const sfx = new Howl({
  src: ['/assets/blip.mp3', '/assets/blip.wav'],
  volume: 0.8
});

// Global settings: mute all sounds and then unmute after a delay
Howler.mute(true);
console.log('All audio is muted globally.');

setTimeout(() => {
  Howler.mute(false);
  console.log('All audio is unmuted. Playing background music and sound effect.');
  bgMusic.play(); // Play background music
  sfx.play();     // Play a sound effect
}, 3000);

// You can also stop all sounds globally if needed
// Howler.stop();

view raw JSON →