Your browser doesn't support the HTML5 audio element. Please upgrade!
Want more?

Documentation: Buzz

Buzz is a small Javascript library that helps you to easily include and manage sounds in your websites using the HTML5 audio tag. It degrades silently on non-modern browsers.

Constructors

new buzz.sound( sources, settings )

Create a new sound instance. See Sound section for more details.

var mySound = new buzz.sound("/sounds/mysound.ogg");

new buzz.group( sounds )

Create a group of sound instances. See Group section for more details.

var myGroup = new buzz.group([ 
    new sound("/sounds/mysound1.ogg"),
    new sound("/sounds/mysound2.ogg"),
    new sound("/sounds/mysound3.ogg")
]);

Methods

buzz.all()

Allow to act on all sound instances. Take a look to the Group section for more details.

var mySound1 = new sound("/sounds/mysound1.ogg"),
    mySound2 = new sound("/sounds/mysound2.ogg"),
    mySound3 = new sound("/sounds/mysound3.ogg");
buzz.all().play();

buzz.isSupported()

Check if the HTML5 audio tag is supported by the browser.

if (!buzz.isSupported()) {
    alert("Your browser is too old, time to update!");
}

buzz.isOGGSupported()

Check if the OGG audio format is supported by the browser.

if (!buzz.isOGGSupported()) {
    alert("Your browser doesn't support OGG Format.");
}

buzz.isWAVSupported()

Check if the WAV audio format is supported by the browser.

if (!buzz.isWAVSupported()) {
    alert("Your browser doesn't support WAV Format.");
}

buzz.isMP3Supported()

Check if the MP3 audio format is supported by the browser.

if (!buzz.isMP3Supported()) {
    alert("Your browser doesn't support MP3 Format.");
}

buzz.isAACSupported()

Check if the AAC audio format is supported by the browser.

if (!buzz.isAACSupported()) {
    alert("Your browser doesn't support AAC Format.");
}

Helpers

buzz.toTimer( seconds, long )

Format seconds in an easy to read timer like 00:00 or 00:00:00 if long is set to true.

var mySound = new buzz.sound("/sounds/mysound.ogg"),
    timer = buzz.toTimer( mySound.getDuration() );
document.getElemetById("duration").innerHTML = timer;

buzz.fromTimer( timer )

Convert a timer as 00:00 or 00:00:00 in seconds.

var mySound = new buzz.sound("/sounds/mysound.ogg");
mySound.setTime( buzz.fromTimer("00:30") );

buzz.toPercent( value, total, round )

Calculate percentage from values.

var mySound  = new buzz.sound("/sounds/mysound.ogg"),
    time     = mySound.getTime(),
    duration = mySound.getDuration(),
    percent  = buzz.toPercent( time, duration, 2 );
document.getElementById("percent").innerHTML = percent;

buzz.fromPercent( value, total, round )

Calculate value from a percentage.

var mySound = new buzz.sound("/sounds/mysound.ogg"),
mySound.setTime( buzz.fromPercent("20", mySound.getDuration() );

Properties

buzz.defaults

Object of properties. All the default settings can be set globaly.

// Preload the sound
// auto, metadata, none
buzz.defaults.preload = 'auto';
// Play the sound when ready
// bool
buzz.defaults.autoplay = false;
// Loop the sound
// bool
buzz.defaults.loop = false;
// value to display when a time convertion is impossible
buzz.defaults.placeholder = '--';
// Duration of a fading effect
// milliseconds
buzz.defaults.duration = 5000; 
// Audio formats of your files
buzz.defaults.formats = ['ogg', 'mp3', 'aac', 'wav'];

buzz.sounds

Array of all the sound instances created.

for(var i in buzz.sounds) {
    buzz.sounds[i].mute();
}

Contact

Library, design & development

Jay Salvat

Dual licensed under the MIT and GPL licenses. In short, do whatever you want with it, as long as you include a visible attribution to Jay Salvat.

Contact me if you need some help with the library. But please note the library is free. I'm not ;)

Credits

Logo and icons

Joker Design

His work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License.

This website uses:

jQuery by John Resign and the jQuery Team

jQuery Ui by the jQuery Team

Thanks to:

Will Stone for his proofreading .