Manager for groupped and alone sounds in CreateJS/SoundJS with SoundJSDirector.
You can install this package via bower:
bower install [email protected]:vasiliy0s/SoundJSDirector.git --save
And it will be install this package to your bower_components directory.
After include of soundjs-director.js
file to your site/app pages you can group sounds (with possible preloading) as in example:
var SoundJSDirector = createjs.SoundJSDirector;
// Create new group with static options, add sounds and load.
new SoundJSDirector.Group('main', {volume: 0.5, collapsed: true})
.add(['assets/sound1.js', 'assets/sound2.js'])
.load();
// Play first free sound 3 times from previously defined group with custom options in another part of your code.
SoundJSDirector.group('main').play({offset: 1, loop: 3});
SoundJSDirector is available in createjs
global object as central manager point:
var SoundJSDirector = createjs.SoundJSDirector;
It provides new Group(name)
constructor, .group(name)
getter and several utilities for library.
This is the named
sounds group definition with possible options:
var group = new SoundJSDirector.Group('main', {
volume: 1,
loop: 0,
delay: 0,
offset: 0,
pan: 0,
collapsed: false,
basePath: '',
});
In code you can see default group options. Most of options you can see is options for SoundJS instances playing and you can read about it in documentation.
Option collapsed
indicate for .play()
method can play only one sound of group.
All of options can be temporary applyed on .play()
method at once (on call) without changing group properties. But all of the options can be changed with .set(name)
group method.
Set name
of group option to value
. All of options will be applyed only with next actions.
Returns name
option of group or group name or group sounds.
Returns sound by id
or src
.
Returns true if sound
(src, id or SoundInstance) exists in group.
Add sounds from manifests
(or array of manifests) to group with createjs.Sound.registerSound(manifest)
and create instances form it.
Register SoundInstance
in group for managing. This is not automatically stops joined instances. (it using SoundJSDirector.setSoundGroup)
Unregister SoundInstance
from group. This is not automatically stops joined instances. (it using SoundJSDirector.unsetSoundGroup)
Ungergister all sounds from group.
Apply callback
funciton (with optional ctx
context) with every group sound.
Apply callback
funciton (with optional ctx
context) with every group sound.
Play all/random/specified sounds in group. Possible usage variants:
.play()
- play all (or random free, if group is collapsed) sounds in group;.play(id)
- play sound in group with sameid
;.play(id, options)
- play sound in group with sameid
withoptions
, passing to playing instance and merged with group options;.play(options[, true])
- play all (or random free, if group is collapsed) sound in group with options, passing to playing instace and merged with group options;options
can containid
orsrc
property for select custom sound from group;true
indicates to force using already playing sounds and can be setted asoptions.all
key;
Pause every playing sound in group.
Resume every playing sound in group.
Stop every playing sound in group.
Set value
volume for group sound. Use all = true
for apply for all of group sound (with not currently playing).
Returns group volume.
Compute volume based on volume
value and all of joined groups settings.
Get defined group by name
for manage.
- Complete README documentation.
- Force sounds loading when .play() is called.
- Create full-featured documentation with any autobuilder.
- Add tests.
- Add version to code.
- Add priorities for sounds.
- Add easings for playback and volume/pan/mute setting group operations.
- Complete another TODOs from code.
- TODO: pass Sound.INTERRUPT's to play() method.
- TODO: provide sounds events in group like 'playing', 'played', 'loaded', other...
I am sorry for my bad English. If you see language errors in documentation, comments or code, please fix'n'contribute or tell me about.
Apache License Version 2.0