SoundJS is designed to have a simple and familiar API. Two new global
constructors are exposed: Sound and
SoundChannel, which are designed to loosely resemble Flash's
Sound
and SoundChannel
API's.
The Sound class is what you will be mostly working with. Playing sounds with
SoundJS starts by loading an audio resource with the new Sound
constructor.
src| String | The absolute or relative location of the audio resource to load.
Begins the loading of an audio resource. The resource begins downloading immediately after the constructor returns.
Sound#play(options) → SoundChannel
options| Object | An Object containing instance options for theSoundChannelto use.
Begins playback of the Sound through a SoundChannel instance. Pass an
optional options Object with any of the values:
offset: The number of milliseconds to start from. Default 0.pan: Value from -1 (full left) to 1 (full right). The left-to-right panning of the sound. Default 0. Note that this property is only used with Flash, so if you MUST usepan, then be sure to setSound.forceFlashtotrue.volume: The volume, ranging from 0 (silent) to 1 (full volume). Default 1.
Gets and returns the total duration of the audio resource, in milliseconds.
false immediately after construction, and throughout loading. true once
the audio resource has finished loading.
The resource path passed into the constructor.
This value is checked every time new Sound is called. If it is set to
true, then playback will be through Flash ONLY. false by default.
The version String of SoundJS. Can be useful for debugging or verification
purposes.
SoundChannel instances are created by calling Sound#play,
not by using the new operator. Once the sound data from a SoundChannel has
been played, or SoundChannel#stop has been called, the
instance is useless (not re-usable).
Stops the SoundChannel from playing it's data. The instance is essentially
useless after calling this, since SoundChannels are not re-usable.
Gets and returns the current point that is being played in the sound file.
Gets and returns the current left-to-right pan of the sound playback.
Gets and returns the volume (from 0 to 1) of the sound playback.
pan| Number | The value to set as the pan.
Sets the left-to-right pan of the sound playback, from -1 (full left) to 1 (full right).
vol| Number | The value to set as the volume.
Sets the playback volume of the sound file (from 0 to 1).