Class: WebAudio

WebAudio

new WebAudio(url)

The audio object of Web Audio API.
NameTypeDescription
urlstringThe url of the audio file

Members

pannumber

The pan of the audio

pitchnumber

The pitch of the audio

urlstringreadonly

The url of the audio file

volumenumber

The volume of the audio

Methods

addLoadListener(listner)

Adds a callback function that will be called when the audio data is loaded
NameTypeDescription
listnerfunctionThe callback function

addStopListener(listner)

Adds a callback function that will be called when the playback is stopped
NameTypeDescription
listnerfunctionThe callback function
Clears the audio data
Destroys the audio

fadeIn(duration)

Performs the audio fade-in
NameTypeDescription
durationnumberFade-in time in seconds

fadeOut(duration)

Performs the audio fade-out
NameTypeDescription
durationnumberFade-out time in seconds

isError()boolean

Checks whether a loading error has occurred
Returns:
TypeDescription
booleanTrue if a loading error has occurred

isPlaying()boolean

Checks whether the audio is playing
Returns:
TypeDescription
booleanTrue if the audio is playing

isReady()boolean

Checks whether the audio data is ready to play
Returns:
TypeDescription
booleanTrue if the audio data is ready to play

play(loop, offset)

Plays the audio
NameTypeDescription
loopbooleanWhether the audio data play in a loop
offsetnumberThe start position to play in seconds
Tries to load the audio again
Gets the seek position of the audio
Stops the audio

WebAudio.initialize()booleanstatic

Initializes the audio system
Returns:
TypeDescription
booleanTrue if the audio system is available

WebAudio.setMasterVolume(value)static

Sets the master volume for all audio
NameTypeDescription
valuenumberThe master volume (0 to 1)