Module: audio

Members

(static, constant) defaults :Object

Default values for durations.
Type:
  • Object
Source:

Methods

(static) clearPlaylist()

Clears the playlist and the music queue. Does not stop music that's currently playing.
Source:

(static) currentMusicPlaying() → {string|null}

Gets the name of the currently playing music file, or null if nothing is playing. If music has been asked to stop, returns the music that will play next.
Source:
Returns:
Type
string | null

(static) fadeOut(element, durationopt, callbackopt) → {boolean}

Fades out sound.
Parameters:
Name Type Attributes Default Description
element string | object The audio element that should fade out
duration number <optional>
1000 The duration of the fade in milliseconds, default 1000 ms (1 second) or the value set in vorple.defaults.fadeDuration. Note that the duration is calculated from 100% volume, even if the current volume of the sound is less than that.
callback function <optional>
Function that is called when the audio has stopped completely with a boolean as the first parameter that matches what this function returned
Source:
Returns:
False if the element doesn't exist or is not an audio element, true otherwise
Type
boolean

(static) isAudioPlaying() → {boolean}

Checks if any audio is playing. Note that sound that is being loaded or has received a play command but isn't playing for some other reason isn't considered as playing, even though it's about to start.
Source:
Returns:
Type
boolean

(static) isEffectPlaying() → {boolean}

Checks if any sound effect is playing.
Source:
Returns:
Type
boolean

(static) isElementPlaying(audioElement) → {boolean}

Checks if an audio element is playing.
Parameters:
Name Type Description
audioElement string | object DOM element, jQuery object or jQuery selector of the audio element
Source:
Returns:
Type
boolean

(static) isMusicPlaying() → {boolean}

Checks if music is playing. Returns true if music is actually playing and it isn't fading out at the moment.
Source:
Returns:
Type
boolean

(static) playMusic(url, optionsopt)

Starts playing music. If the same music file is already playing, does nothing except sets the looping property. If another music file is playing, fades out the old one before playing the new one.
Parameters:
Name Type Attributes Default Description
url string
options object <optional>
{}
Properties
Name Type Attributes Default Description
looping boolean <optional>
false If true, the track keeps repeating
restart boolean <optional>
false If true, always starts playing from the start, even when this track is already playing
Source:

(static) playSound(url, optionsopt) → {object}

Starts playing a sound effect.
Parameters:
Name Type Attributes Default Description
url string
options object <optional>
{}
Properties
Name Type Attributes Default Description
id string <optional>
"" The id to attach to the audio element
looping boolean <optional>
false If true, the sound effect keeps repeating
Source:
Returns:
The audio DOM element
Type
object

(static) setPlaylist(list, optionsopt)

Sets a playlist and starts playing it.
Parameters:
Name Type Attributes Default Description
list Array.<string> An array of music file URLs
options object <optional>
{}
Properties
Name Type Attributes Default Description
looping boolean <optional>
false If true, the playlist starts playing again from the start when it ends
restart boolean <optional>
false If true, always play from the start even when a track in the playlist is already playing
shuffle boolean <optional>
false If true, shuffles the playlist in random order before playing it
Source:

(static) stopMusic(fadeoutDurationopt)

Stops playing music. Clears the music queue and the playlist.
Parameters:
Name Type Attributes Default Description
fadeoutDuration number <optional>
1000 The duration of the fadeout. Set to 0 to stop immediately.
Source: