19

There are a number of JavaScript libraries available for HTML5 audio, to either make a developer's life easier, ensure cross-browser compatibility or support Flash fallback for older browsers.

I haven't found much in terms of comparatives, except maybe for this article, on a small scale.

Which of the following libraries come recommended and for what purposes? What can I expect in terms of documentation and support (eg: is that library likely here to stay?)

I don't need UI features for my needs and would rather keep things small and simple. That would seem to make Audio5JS a candidate of choice. However I'm wondering if that's a smart choice simply because it doesn't seem to have as big a community as, say, jPlayer.

EDIT: I simply need to play an audio file (in full and/or parts of it) based on user input and the ability to loop that for a given file (ie: loop the file itself or loop a part of it.)

General guidelines on how to pick a JS library to get a job done will also be welcome.

I mainly wanna save myself the need to try out all those libraries (and more) to figureout their pro's and con's.

Thank you.

Fabien Snauwaert
  • 4,995
  • 5
  • 52
  • 70
  • If someone is only looking for a web audio api based then solution they can checkout http://musquitojs.com/ – VJAI Jun 25 '18 at 15:47

3 Answers3

9

You may have already selected a library, but as the developer of howler.js, I thought I'd leave a note. From your description, I'd say howler.js is exactly what you are looking for if you don't need less than IE9 support. howler.js has now been under development/refinement for nearly a year and has a large community around it. It is great for both simple and complex tasks, and leaves any UI needs up to the developer. howler.js is currently the only library that I'm aware of that lets you seamlessly use both Web Audio API and HTML5 Audio with a single, simple API.

James Simpson
  • 13,488
  • 26
  • 83
  • 108
  • SoundJS also lets you use Web Audio and HTML audio with a single API, with an optional flash fallback for older browsers. Nice work on Howler, I like your implementation of audio sprites. – OJay Mar 12 '14 at 22:19
  • 1
    Good work indeed with sound sprites! I was wondering if you are planning to add pre-loading of sounds as part of howler, or if you instead recommend going with something like PreloadJS. – wavicle May 19 '14 at 22:03
  • I'm currently working on howler.js 2.0 (though progress is slow as I'm currently swamped with my startup), and this is something I'm going to be paying more attention to. – James Simpson May 20 '14 at 14:43
  • 2
    @Andreas It most certainly does. We are using it in production with tens of thousands using it on IE11, and thousands of other developers are too. – James Simpson Nov 05 '14 at 22:41
  • 1
    I know my fault. Forgot to come back and comment howler is awesome but developers should know that they have to go through the documentation for each browser. Eg. a few minutes after my comment I dived into IE documentation for multimedia and realized that that I only needed to convert them to m4a in order to use them(I was using .ogg). I apologize for not commenting back earlier and thanks for sharing this awesome library. – Andreas Nov 06 '14 at 19:36
  • I also recommend converting files using gnome Sound Converter. That's the simplest and fastest solution – Andreas Nov 06 '14 at 19:39
  • Thanks, glad you got it working! This is something that is being improved with 2.0, there's a section in the docs that makes this much more clear. – James Simpson Nov 07 '14 at 13:45
1

My recommendation would be SoundJS, but I may be biased because I work on it.

It allows you to get audio up and running with minimal code that will work across all modern browsers. Looping and playing from an offset both work smoothly. As far as I know, looping only a slice of a larger audio file smoothly can only be done with pure web audio, which currently is only supported in Chrome and Safari. SoundJS doesn't support that functionality directly, but does allow you access the web audio nodes directly so you can set it up manually.

Hope that helps.

OJay
  • 1,249
  • 7
  • 14
0

You can also check out http://musquitojs.com/. It provides a simple API to create and play sounds.

For example, to play a sound all you've to do is.

import $buzz from 'musquito';

$buzz.play('gunfire.mp3');

The library also supports Audio Sprites.

VJAI
  • 32,167
  • 23
  • 102
  • 164