Toolkit:sound

From Surebert wiki

Contents

Overview

sb.sound allows you to play mp3 files by harnassing the power of Adobe Flash Player from javascript.

Simple Example

Creating a button that plays a sounds when pressed

javascript code

sb.include('sound');
var button = new sb.element({
        tag : 'button',
        innerHTML : 'get sprung',
        onclick : function(){
                new sb.sound({url : '/url/of/your/sound.mp3'}).play();
        }
}).appendTo('body');

Static Properties

The static properties and methods belong directly to sb.sound

sounds

An array of all sounds instances of the page

javascript code

sb.sound.forEach(function(sound){
	//do something with the sound
	sound.stop();
});

Static Methods

muteAll()

Mutes every sounds instance

javascript code

sb.sound.muteAll();

setGlobalVolume()

Sets the global volume for all sound instances

javascript code

sb.sound.setGlobalVolume(20);

stopAll()

Stops all sounds instances from playing

javascript code

sb.sound.stopAll();

Prototype Properties

The prototype properties and methods belong to instances of sb.sound

url

The url of the mp3 file to be played.

id

The id of the sounds being played. This is how surebert keeps track of the sounds internally.

duration

The duration of the sound in milliseconds, available after the sound has loaded.

Prototype Methods

getPan()

Gets the current pan position. float between -1 (left) and 1 (right)

javascript code

mySound.getPan();

getPosition()

Gets the current position in milliseconds

getPositionPercent()

Gets the current position in percent

getVolume

Gets the volume Float between 0 and 1

mute()

Mutes the sound

play()

Plays the sound

setPan(pan)

Set the pan on the sound float between -1 (left) and 1 (right)

setPosition(milliseconds)

Sets the position of the playhead in milliseconds

setPositionPercent(percent)

Sets the position of the playhead in milliseconds

setVolume(volume)

Sets the volume of the sound Float volume between 0 and 1

javascript code

mySound.setVolume(0.5);

stop()

Stops the sound

Prototype Event Handlers

onError(message)

Fires when their is an error loading the mp3

javascript code

mySound.onError = function(message){
	alert(message);
}

onID3(tags)

Fires when the ID3 info is loaded from the mp3 The following information is passed as an object argument to the handler tags.album, tags.year, tags.artist, tags.songName, tags.comment, tags.track, tags.genre

javascript code

mySound.onID3 = function(tags){
	alert(tags.artist);
}

onLoad(song)

Fires when the mp3 is loaded The following properties are passed as an object argument to onID3(). song.sizeK, song.bytesLoaded, song.bytesTotal

javascript code

mySound.onLoad = function(song){
	alert(song.sizeK);
}

onProgress(song)

Fires when the mp3 progresses The following properties are passed as an object argument to onProgress(). song.position, song.length, song.percent

javascript code

mySound.onProgress = function(song){
	alert(song.percent);
}