new b5.Sound(name, location, reuse){b5.Sound}
A Sound represents a sound effect object and can be used to play back audio
Generally a sound should be added to either a b5.Scene or the global b5.App's resources so that it can be managed by them.
Example showing how to load and play a sound effect
var sound = new b5.Sound("explosion", "sounds/explosion.mp3", true);
var instance = sound.play();
For a complete overview of Resources see Booty5 Resources Overview
Name | Type | Description |
---|---|---|
name |
string |
Name of sound resource |
location |
string |
The sound file location |
reuse |
boolean |
Mark the sound to be re-used (only one single instance will ever be created if true) |
Properties:
Name | Type | Description |
---|---|---|
parent |
b5.App | b5.Scene | Parent resource manager (internal) |
snd |
object | Sound instance (re-usable sound only) (internal). For Web Audio stores a {source:AudioBufferSourceNode, gain:GainNode} object for auto play sounds |
buffer |
object | AudioBufferSourceNode containing decoded audio data (Web Audio only) |
name |
string | Name of this sound resource |
location |
string | The location of the sound file that is used to create the audio object |
location2 |
string | The location of the sound file that is used as a fall back if sound at location does not load |
reuse |
boolean | When set to false the generated sound Audio will be re-used, this can prevent sounds that are currently playing being replayed whilst currently being played but can help resolve audio playback issues (Not used by Web Audio) |
loop |
boolean | If set to true then sound will be looped |
preload |
boolean | If set to true then this sound will be preloaded |
auto_play |
boolean | If set to true then this sound will be preloaded |
loaded |
boolean | If true then this resource has finished loading |
Returns:
Type | Description |
---|---|
b5.Sound | The created sound |
Members
-
staticb5.Sound.contextobject
-
AudioContext used by Web Audio API
Methods
-
staticb5.Sound.init(){boolean}
resource/sound.js, line 75 -
Initialises the sound system
Returns:
Type Description boolean true for success or false if error -
staticb5.Sound.isSupported(filename){boolean}
resource/sound.js, line 103 -
Checks if the supplied audio file type is supported
Name Type Description filename
string Name of audio file
Returns:
Type Description boolean true if probably supported, false if not -
destroy()
resource/sound.js, line 245 -
Removes the sound from the scene / app and destroys it
-
load()
resource/sound.js, line 119 -
Loads the sound
-
pause()
resource/sound.js, line 236 -
Pauses playback of the sound (re-usable sound only)
-
play(){object}
resource/sound.js, line 188 -
Starts playback of the sound
Returns:
Type Description object An Audio object representing the playing sound or a {source, gain} object if using Web Audio API -
stop()
resource/sound.js, line 227 -
Stops playback of thr sound (re-usable sound only)