API Documentation for: 0.5.2
Show:

WebAudioPlugin Class

Defined in: WebAudioPlugin:41
Module: SoundJS

Available since 0.4.0

Play sounds using Web Audio in the browser. The WebAudioPlugin is currently the default plugin, and will be used anywhere that it is supported. To change plugin priority, check out the Sound API registerPlugins method.

Known Browser and OS issues for Web Audio

Firefox 25

  • mp3 audio files do not load properly on all windows machines, reported here.
    For this reason it is recommended to pass another FF supported type (ie ogg) first until this bug is resolved, if possible.

Webkit (Chrome and Safari)
  • AudioNode.disconnect does not always seem to work. This can cause the file size to grow over time if you are playing a lot of audio files.

iOS 6 limitations
  • Sound is initially muted and will only unmute through play being called inside a user initiated event (touch/click).
  • A bug exists that will distort uncached audio when a video element is present in the DOM. You can avoid this bug by ensuring the audio and video audio share the same sampleRate.

Constructor

WebAudioPlugin

()

Defined in WebAudioPlugin:41

Available since 0.4.0

Methods

_compatibilitySetUp

() protected

Defined in _compatibilitySetUp:197

Available since 0.4.2

Set up compatibility if only deprecated web audio calls are supported. See http://www.w3.org/TR/webaudio/#DeprecationNotes Needed so we can support new browsers that don't support deprecated calls (Firefox) as well as old browsers that don't support new calls.

_generateCapabilities

() protected static

Determine the capabilities of the plugin. Used internally. Please see the Sound API getCapabilities method for an overview of plugin capabilities.

_handlePreloadComplete

() protected

Handles internal preload completion.

_init

() protected

Defined in _init:308

An initialization function run by the constructor

_isFileXHRSupported

() Boolean protected static

Defined in _isFileXHRSupported:101

Available since 0.4.2

Determine if XHR is supported, which is necessary for web audio.

Returns:

Boolean: If XHR is supported.

_updateVolume

() protected

Defined in _updateVolume:441

Set the gain value for master audio. Should not be called externally.

addPreloadResults

(
  • src
)
Boolean

Add loaded results to the preload object hash.

Parameters:

  • src String

    The sound URI to unload.

Returns:

create

(
  • src
)
SoundInstance

Defined in create:415

Create a sound instance. If the sound has not been preloaded, it is internally preloaded here.

Parameters:

  • src String

    The sound source to use.

Returns:

SoundInstance: A sound instance for playback and control.

getVolume

()

Defined in getVolume:453

Get the master volume of the plugin, which affects all SoundInstances.

Returns:

The volume level, between 0 and 1.

isPreloadComplete

(
  • src
)
Boolean

Checks if preloading has finished for a specific source.

Parameters:

  • src String

    The sound URI to load.

Returns:

isPreloadStarted

(
  • src
)
Boolean

Checks if preloading has started for a specific source. If the source is found, we can assume it is loading, or has already finished loading.

Parameters:

  • src String

    The sound URI to check.

Returns:

isSupported

() Boolean static

Defined in isSupported:83

Determine if the plugin can be used in the current browser/OS.

Returns:

Boolean: If the plugin can be initialized.

playEmptySound

()

Defined in playEmptySound:223

Available since 0.4.1

Plays an empty sound in the web audio context. This is used to enable web audio on iOS devices, as they require the first sound to be played inside of a user initiated event (touch/click). This is called when WebAudioPlugin is initialized (by Sound initializeDefaultPlugins for example).

Example

function handleTouch(event) {
    createjs.WebAudioPlugin.playEmptySound();
}

preload

(
  • src
  • instance
)

Defined in preload:402

Internally preload a sound. Loading uses XHR2 to load an array buffer for use with WebAudio.

Parameters:

  • src String

    The sound URI to load.

  • instance Object

    Not used in this plugin.

register

(
  • src
  • instances
)
Object

Defined in register:322

Pre-register a sound for preloading and setup. This is called by Sound. Note that WebAudio provides a Loader instance, which PreloadJS can use to assist with preloading.

Parameters:

  • src String

    The source of the audio

  • instances Number

    The number of concurrently playing instances to allow for the channel at any time. Note that the WebAudioPlugin does not manage this property.

Returns:

Object: A result object, containing a "tag" for preloading purposes.

removeAllSounds

(
  • src
)

Defined in removeAllSounds:371

Available since 0.4.1

Remove all sounds added using register. Note this does not cancel a preload.

Parameters:

  • src String

    The sound URI to unload.

removeSound

(
  • src
)

Defined in removeSound:361

Available since 0.4.1

Remove a sound added using register. Note this does not cancel a preload.

Parameters:

  • src String

    The sound URI to unload.

setMute

(
  • value
)
Boolean

Defined in setMute:462

Mute all sounds via the plugin.

Parameters:

  • value Boolean

    If all sound should be muted or not. Note that plugin-level muting just looks up the mute value of Sound getMute, so this property is not used here.

Returns:

Boolean: If the mute call succeeds.

setVolume

(
  • value
)
Boolean

Defined in setVolume:428

Set the master volume of the plugin, which affects all SoundInstances.

Parameters:

  • value Number

    The volume to set, between 0 and 1.

Returns:

Boolean: If the plugin processes the setVolume call (true). The Sound class will affect all the instances manually otherwise.

Properties

_arrayBuffers

Object protected

Defined in _arrayBuffers:297

An object hash used internally to store ArrayBuffers, indexed by the source URI used to load it. This prevents having to load and decode audio files more than once. If a load has been started on a file, arrayBuffers[src] will be set to true. Once load is complete, it is set the the loaded ArrayBuffer instance.

_capabilities

Object protected static

Defined in _capabilities:72

The capabilities of the plugin. This is generated via the _generateCapabilities method and is used internally.

Default: null

_panningModel

Number / String protected

Defined in _panningModel:274

Value to set panning model to equal power for SoundInstance. Can be "equalpower" or 0 depending on browser implementation.

_volume

Number protected

Defined in _volume:256

The internal master volume value of the plugin.

Default: 1

context

AudioContext

Defined in context:266

The web audio context, which WebAudio uses to play audio. All nodes that interact with the WebAudioPlugin need to be created within this context.

dynamicsCompressorNode

AudioNode

A DynamicsCompressorNode, which is used to improve sound quality and prevent audio distortion. It is connected to context.destination.

gainNode

AudioGainNode

Defined in gainNode:290

A GainNode for controlling master _volume. It is connected to dynamicsCompressorNode.