waud.js
API Docs for v1.0.3
Show:

Waud

Defined in: src/Waud.hx:6

Summary

Web Audio Library with HTML5 audio fallback.

Item Index

Methods

Properties

Methods

autoMute

Defined in src/Waud.hx:258

Syntax

autoMute

() static

Summary

Helper function to automatically mute audio when the browser window is not in focus.

Will un-mute when the window gains focus.

Example:

Waud.autoMute();

destroy

Defined in src/Waud.hx:555

Syntax

destroy

() static

Summary

Function to destroy audio context.

Example:

Waud.destroy();

enableTouchUnlock

Defined in src/Waud.hx:280

Syntax

enableTouchUnlock

(
  • [callback]
)
static

Summary

Helper function to unlock audio on iOS devices.

You can pass an optional callback which will be triggered after unlocking audio.

Parameters:

  • [callback] Function optional
    • Optional callback that triggers after unlocking audio.

Example:

Waud.enableTouchUnlock(callback);

getFormatSupportString

Defined in src/Waud.hx:437

Syntax

getFormatSupportString

() String static

Summary

Returns a string with all the format support information.

Returns:

String:

support string OGG: probably, WAV: probably, MP3: probably, AAC: probably, M4A: maybe (example)

Example:

Waud.getFormatSupportString();

getSampleRate

Defined in src/Waud.hx:542

Syntax

getSampleRate

() Float static

Summary

Function to get current sample rate of audio context.

Returns:

Float:

sample rate

Example:

Waud.getSampleRate();

getVolume

Defined in src/Waud.hx:313

Syntax

getVolume

() Float static

Summary

Function to get global volume.

Returns:

Float:

between 0 and 1

Example:

Waud.getVolume();

init

Defined in src/Waud.hx:206

Syntax

init

(
  • [d = document]
)
static

Summary

To initialise the library, make sure you call this first.

You can also pass an optional parent DOM element to it where all the HTML5 sounds will be appended and also used for touch events to unlock audio on iOS devices.

Parameters:

Example:

Waud.init();

isAACSupported

Defined in src/Waud.hx:514

Syntax

isAACSupported

() Bool static

Summary

Function to check aac format support.

Returns:

Bool:

true or false

Example:

Waud.isAACSupported();

isM4ASupported

Defined in src/Waud.hx:528

Syntax

isM4ASupported

() Bool static

Summary

Function to check m4a format support.

Returns:

Bool:

true or false

Example:

Waud.isM4ASupported();

isMP3Supported

Defined in src/Waud.hx:500

Syntax

isMP3Supported

() Bool static

Summary

Function to check mp3 format support.

Returns:

Bool:

true or false

Example:

Waud.isMP3Supported();

isOGGSupported

Defined in src/Waud.hx:472

Syntax

isOGGSupported

() Bool static

Summary

Function to check ogg format support.

Returns:

Bool:

true or false

Example:

Waud.isOGGSupported();

isSupported

Defined in src/Waud.hx:455

Syntax

isSupported

() Bool static

Summary

Function to check whether audio is supported or not.

Returns:

Bool:

true or false

Example:

Waud.isSupported();

isWAVSupported

Defined in src/Waud.hx:486

Syntax

isWAVSupported

() Bool static

Summary

Function to check wav format support.

Returns:

Bool:

true or false

Example:

Waud.isWAVSupported();

mute

Defined in src/Waud.hx:326

Syntax

mute

(
  • [val = true]
)
static

Summary

Helper function to mute all the sounds.

Parameters:

  • [val = true] Bool optional

Example:

Waud.mute();
Waud.mute(true);
Waud.mute(false);

pause

Defined in src/Waud.hx:373

Syntax

pause

() static

Summary

Helper function to pause all the sounds.

Example:

Waud.pause();

playbackRate

Defined in src/Waud.hx:344

Syntax

playbackRate

(
  • [val]
)
Float static

Summary

Helper function to set playback rate of all the sounds.

Parameters:

  • [val] Float optional

Returns:

Float:

current playback rate.

Example:

Waud.playbackRate();
Waud.playbackRate(1.25);

playSequence

Defined in src/Waud.hx:385

Syntax

playSequence

(
  • snds
  • [onComplete]
  • [onSoundComplete]
  • [interval]
)
static

Summary

Helper function to play sounds sequentially. This function assumes sounds are already initialised and loaded.

Parameters:

  • snds Array
    • Array of sounds to play sequentially
  • [onComplete] Function optional
    • Optional callback that triggers after playing all sounds in the sequence.
  • [onSoundComplete] Function optional
    • Optional callback that triggers after playing each sounds in the sequence.
  • [interval] Int optional
    • Optional interval in milliseconds to play sequence. Use this to play sounds in set interval instead of waiting for the previous sound to finish.

Example:

Waud.playSequence(["snd1", "snd2", "snd3"]);
Waud.playSequence(["snd1", "snd2", "snd3"], onComplete);
Waud.playSequence(["snd1", "snd2", "snd3"], onComplete, onSoundComplete);
Waud.playSequence(["snd1", "snd2", "snd3"], 500);

setVolume

Defined in src/Waud.hx:296

Syntax

setVolume

(
  • val
)
static

Summary

Function to set global volume.

Parameters:

  • val Float
    • Should be between 0 and 1.

Example:

Waud.setVolume(0.5);

stop

Defined in src/Waud.hx:361

Syntax

stop

() static

Summary

Helper function to stop all the sounds.

Example:

Waud.stop();

Properties

__audioElement

Defined in src/Waud.hx:163

Syntax

__audioElement

AudioElement private static

Summary

Audio element used to check audio support.

__touchUnlockCallback

Defined in src/Waud.hx:153

Syntax

__touchUnlockCallback

Function protected static

Summary

Touch unlock callback reference.

_focusManager

Defined in src/Waud.hx:184

Syntax

_focusManager

WaudFocusManager private static

Summary

Focus Manager reference used for autoMute functionality.

_playbackRate

Defined in src/Waud.hx:174

Syntax

_playbackRate

Float private static

Summary

Global playback rate.

_volume

Defined in src/Waud.hx:195

Syntax

_volume

Float private static

Summary

Current global volume.

audioContext

Defined in src/Waud.hx:121

Syntax

audioContext

AudioContext static

Summary

Audio Context reference.

audioManager

Defined in src/Waud.hx:111

Syntax

audioManager

AudioManager static

Summary

Audio Manager instance.

defaults

Defined in src/Waud.hx:65

Syntax

defaults

WaudSoundOptions static

Summary

Defaults properties used on sound.

Default: { autoplay: false, loop: false, preload: true, webaudio: true, volume: 1 }

Example:

Waud.defaults = { volume: 0.5, autoplay: true, preload: false };

dom

Defined in src/Waud.hx:131

Syntax

dom

Document static

Summary

Document dom element used for appending sounds and touch events.

isHTML5AudioSupported

Defined in src/Waud.hx:53

Syntax

isHTML5AudioSupported

Bool static

Summary

Tells whether html5 audio is supported or not.

Example:

Waud.isHTML5AudioSupported;

isMuted

Defined in src/Waud.hx:140

Syntax

isMuted

Bool static

Summary

State of audio, muted or not.

Default: false

Example:

Waud.isMuted;

isWebAudioSupported

Defined in src/Waud.hx:41

Syntax

isWebAudioSupported

Bool static

Summary

Tells whether web audio api is supported or not.

Example:

Waud.isWebAudioSupported;

preferredSampleRate

Defined in src/Waud.hx:97

Syntax

preferredSampleRate

Int static

Summary

Preferred sample rate used when creating buffer on audio context.

It is recommended to use audio files with same sample rate and set the value used here.

Default: 44100

Example:

Waud.preferredSampleRate = 22050;

sounds

Defined in src/Waud.hx:85

Syntax

sounds

Map static

Summary

Holds all the sounds that are loaded.

Example:

Waud.sounds.get("url");

useWebAudio

Defined in src/Waud.hx:25

Syntax

useWebAudio

Bool static

Summary

Tells whether to use web audio api or not.

You can use this to enable/disable web audio globally for all sounds.

Note that you can also enable/disable web audio individually for each sound instance.

Default: true

Example:

Waud.useWebAudio = false;

version

Defined in src/Waud.hx:16

Syntax

version

String static

Summary

Version number.