Class: WebAudio

WebAudio(url)

new WebAudio(url)

The audio object of Web Audio API.
Parameters:
Name Type Description
url String The url of the audio file
Properties:
Name Type Description
url String [read-only] The url of the audio file.
volume Number The volume of the audio.
pitch Number The pitch of the audio.
pan Number The pan of the audio.

Methods

(static) canPlayM4a() → {Boolean}

Checks whether the browser can play m4a files.
Returns:
True if the browser can play m4a files
Type
Boolean

(static) canPlayOgg() → {Boolean}

Checks whether the browser can play ogg files.
Returns:
True if the browser can play ogg files
Type
Boolean

(static) initialize(noAudio) → {Boolean}

Initializes the audio system.
Parameters:
Name Type Description
noAudio Boolean Flag for the no-audio mode
Returns:
True if the audio system is available
Type
Boolean

(static) setMasterVolume(value)

Sets the master volume of the all audio.
Parameters:
Name Type Description
value Number Master volume (min: 0, max: 1)

addLoadListener(listner)

Add a callback function that will be called when the audio data is loaded.
Parameters:
Name Type Description
listner function The callback function

addStopListener(listner)

Add a callback function that will be called when the playback is stopped.
Parameters:
Name Type Description
listner function The callback function

clear()

Clears the audio data.

fadeIn(duration)

Performs the audio fade-in.
Parameters:
Name Type Description
duration Number Fade-in time in seconds

fadeOut(duration)

Performs the audio fade-out.
Parameters:
Name Type Description
duration Number Fade-out time in seconds

initialize()

isError() → {Boolean}

Checks whether a loading error has occurred.
Returns:
True if a loading error has occurred
Type
Boolean

isPlaying() → {Boolean}

Checks whether the audio is playing.
Returns:
True if the audio is playing
Type
Boolean

isReady() → {Boolean}

Checks whether the audio data is ready to play.
Returns:
True if the audio data is ready to play
Type
Boolean

play(loop, offset)

Plays the audio.
Parameters:
Name Type Description
loop Boolean Whether the audio data play in a loop
offset Number The start position to play in seconds

seek()

Gets the seek position of the audio.

stop()

Stops the audio.