SoundSystem

SoundSystem

A basic HTML5 sound system for playing sounds and music. To play a sound first add it with addSound, giving it a name, then call playSound with the name you gave it.

To play and loop a music track use addMusic and playMusic.


Constructor

new SoundSystem(musicIntervalSecondsopt)

Basic HTML5 Audio sound system

Parameters:
Name Type Attributes Default Description
musicIntervalSeconds Number <optional>
60

Default is 60.

Members

(static) _musicInterval

default is 60

(static) _trackPaused

_currentTrack

_soundIndex

_soundNames

_soundPlaying

_sounds

_soundTracks

_trackTimer

Methods

addMusic(soundLocation, vol, loop)

Add a music track to be played with playMusic. The first track you add would be at index 0 in _soundTracks, and additional calls are adding to _soundTracks.

Parameters:
Name Type Description
soundLocation String

The url location of the music track.

vol Number

The volume of the track, 0 to 1.

loop Boolean

Default is true

addSound(soundLocation, name, vol, poolAmount)

Add a sound to be played with playSound

Parameters:
Name Type Description
soundLocation String

The Location of the sound to add.

name String

A name for the sound

vol Number

The volume of the sound 0 to 1.

poolAmount Number

Amount to pre load, alows for faster one shots, default is 1.

clearAllSounds()

Clear all sounds added with addSound

clearMusicTracks()

Clears all music added with addMusic.

playMusic(indexopt)

play a music track added with addMusic

Parameters:
Name Type Attributes Default Description
index Number <optional>
0

The index of the track to play, the first track added with addMusic is at index 0, the default is index 0.

playSound(name, usePool)

play a sound added with addSound

Parameters:
Name Type Description
name String

The name of the sound to play, as defined during addSound

usePool Boolean

If true, and you set a poolAmount during addSound, it will cycle through the preloaded pool, otherwise the sound will need to have finished first, before replay. If what you want is fast one shots of the same sound that potentially overlap, then use a pool of 2 or up to 10.

stopMusic()

Stops the currrent music track from playing.