API Documentation for: 0.4.0
Show:

WebAudioPlugin Class

Defined in: WebAudioPlugin:39
Module: SoundJS

Available since 0.4.0

Play sounds using Web Audio in the browser. The WebAudio plugin has been successfully tested with:

  • Google Chrome, version 23+ on OS X and Windows
  • Safari 6+ on OS X
  • Mobile Safari on iOS 6+

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 Plugin

Webkit (Chrome and Safari)

  • AudioNode.disconnect does not always seem to work. This can cause your 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).

Constructor

WebAudioPlugin

()

Defined in WebAudioPlugin:39

Available since 0.4.0

Methods

addPreloadResults

(
  • src
)
Boolean

Add loaded results to the preload hash.

Parameters:

  • src String

    The sound URI to unload.

Returns:

create

(
  • src
)
SoundInstance

Defined in create:294

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.

generateCapabiities

() protected static

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

getVolume

()

Defined in getVolume:332

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

Returns:

The volume level, between 0 and 1.

handlePreloadComplete

() private

Handles internal preload completion.

init

() private

Defined in init:195

An initialization function run by the constructor

isPreloadComplete

(
  • src
)
Boolean

Checks if preloading has finished for a specific source. If the source is defined (but not === true), then it has finished loading.

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:77

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

Returns:

Boolean: If the plugin can be initialized.

preload

(
  • src
  • instance
)
protected

Defined in preload:280

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:209

Pre-register a sound for preloading and setup. This is called by Sound. Note that WebAudio provides a WebAudioLoader 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.

removeFromPreload

(
  • src
)
Boolean

Remove a source from our preload list. Note this does not cancel a preload.

Parameters:

  • src String

    The sound URI to unload.

Returns:

setMute

(
  • value
)
Boolean

Defined in setMute:341

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 Sound/masterMute, so this property is not used here.

Returns:

Boolean: If the mute call succeeds.

setVolume

(
  • value
)
Boolean

Defined in setVolume:307

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.

updateVolume

() protected

Defined in updateVolume:320

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

Properties

arrayBuffers

Object protected

Defined in arrayBuffers:185

A 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 static

Defined in capabilities:67

The capabilities of the plugin. This is generated via the "WebAudioPlugin/generateCapabilities method.

Default: null

context

AudioContext

Defined in context:162

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 and prevent audio distortion according to http://www.w3.org/TR/webaudio/#DynamicsCompressorNode. It is connected to context.destination.

gainNode

AudioGainNode

Defined in gainNode:178

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

volume

Number protected

Defined in volume:153

The internal volume value of the plugin.

Default: 1