soundService

AngularJS Service for playing sounds using Howler.js

Members

(static) sounds

Stored list of sounds, with sound ID and Howler object.

Properties:
Name Type Description
sounds[].id string

A sound ID.

sounds[].howl Object

A Howler sound object.

Source:

(static) pauseArray

Stored list of paused sound IDs.

Source:

Methods

(static) find(id) → (nullable) {Object}

Find an object from module:soundService.sounds.

Source:
Parameters:
Name Type Description
id string

A sound ID.

Returns:
Type:
Object

Sound object if found.

(static) findAndCall(id, callback) → (nullable) {*}

Find an object from module:soundService.sounds and execute a callback with it.

Source:
Parameters:
Name Type Description
id string

A sound ID.

callback function

A callback to run on the found audio object.

Returns:
Type:
*

The return value of the callback, if sound is found.

(static) playRandom(idArr, settingsopt)

Play a sound randomly from a list.

Source:
Parameters:
Name Type Attributes Description
idArr Array.<string>

An array of sound IDs.

settings Object <optional>

Sound settings to use (see module:soundService.play).

(static) play(id, settingsopt)

Play a specific sound.

Source:
Parameters:
Name Type Attributes Description
id string

A sound ID.

settings Object <optional>

Sound settings to use.

Name Type Attributes Description
loop boolean <optional>

Whether to loop the sound.

volume number <optional>

The sound volume (0.0-1.0).

onComplete function <optional>

Callback to run on sound end.

delay number <optional>

Delay before playing (milliseconds).

(static) fade(id, settingsopt)

Fade a specific sound.

Source:
Parameters:
Name Type Attributes Description
id string

A sound ID.

settings Object <optional>

Sound settings to use.

Name Type Attributes Description
from number <optional>

Initial sound volume (0.0-1.0).

to number <optional>

Final sound volume (0.0-1.0).

duration number <optional>

Length of fade (milliseconds).

onComplete function <optional>

Callback to run on fade end.

(static) isPlaying(id) → (nullable) {boolean}

Check if a sound is playing.

Source:
Parameters:
Name Type Description
id string

A sound ID.

Returns:
Type:
boolean

(static) stopAll()

Stop all sounds.

Source:

(static) stop(id)

Stop a specific sound.

Source:
Parameters:
Name Type Description
id string

A sound ID.

(static) pause(id)

Pause a specific sound.

Source:
Parameters:
Name Type Description
id string

A sound ID.

(static) resume(id)

If given an id it will resume that sound if it is paused else it will resume all paused sounds.

Source:
Parameters:
Name Type Description
id string

A sound ID.

(static) muteAll(mute)

Mute all sounds.

Source:
Parameters:
Name Type Description
mute boolean

Whether or not to mute.

(static) muteMultiple(arr, mute)

Mute all sounds in a list.

Source:
Parameters:
Name Type Description
arr Array.<string>

An array of sound IDs.

mute boolean

Whether or not to mute.

(static) mute(id, mute)

Mute a specific sound.

Source:
Parameters:
Name Type Description
id string

A sound ID.

mute boolean

Whether or not to mute.

(static) load(options)

Load a sound.

Source:
Parameters:
Name Type Description
options Object
Name Type Attributes Default Description
id string

The sound ID.

src string

The URL to the sound.

autoplay boolean <optional>
false

Whether to autoplay the sound after load.

volume number <optional>
1.0

The sound volume (0.0-1.0).

loop boolean <optional>
false

Whether to loop the sound.

html5 boolean <optional>
false

Whether to force HTML5 audio.

preload boolean <optional>
true

Whether to preload the sound.

onLoad function <optional>

Callback to run when sound is loaded.

(static) loadMultiple(data)

Load multiple sounds from a list.

Source:
Parameters:
Name Type Description
data Array.<Object>

An array of objects to pass to module:soundService.load.

(static) unload(id)

Unload a sound.

Source:
Parameters:
Name Type Description
id string

A sound ID.

(static) unloadAll()

Unload all sounds.

Source:

(static) reset()

Unload all sounds and clear pause data.

Source:

(static) setVolume(id, volume)

Set the volume for a specific sound.

Source:
Parameters:
Name Type Description
id string

A sound ID.

volume number

The sound volume (0.0-1.0).

(static) getVolume(id) → (nullable) {number}

Get the volume for a specific sound.

Source:
Parameters:
Name Type Description
id string

A sound ID.

Returns:
Type:
number

The sound volume (0.0-1.0).

(static) setRate(id, rate)

Set the rate for a specific sound, used for dynamic pitch shifting.

Source:
Parameters:
Name Type Description
id string

A sound ID.

rate number

The sound rate (0.5-4.0).

(static) checkLoadCompletion() → {number}

Check load progress of all sounds.

Source:
Returns:
Type:
number

The percentage of sounds that are done loading (0.0-1.0).