Namespace: audio

me. audio

There is no constructor function for me.audio.
Source:
audio.js, line 11

Classes

Error

Methods

<static> disable()

disable audio output
Source:
audio.js, line 115

<static> enable()

enable audio output
only useful if audio supported and previously disabled through
Source:
audio.js, line 101
See:
  • me.audio#disable

<static> fade(sound_name, from, to, duration, id)

Fade a currently playing sound between two volumee.
Parameters:
Name Type Argument Description
sound_name String audio clip name - case sensitive
from Number Volume to fade from (0.0 to 1.0).
to Number Volume to fade to (0.0 to 1.0).
duration Number Time in milliseconds to fade.
id Number <optional>
the sound instance ID. If none is passed, all sounds in group will fade.
Source:
audio.js, line 212

<static> getCurrentTrack() → {String}

returns the current track Id
Source:
audio.js, line 435
Returns:
audio track name
Type
String

<static> getVolume() → {Number}

get the default global volume
Source:
audio.js, line 459
Returns:
current volume value in Float [0.0 - 1.0] .
Type
Number

<static> init(audioFormat) → {Boolean}

Initialize and configure the audio support.
melonJS supports a wide array of audio codecs that have varying browser support : ("mp3", "mpeg", opus", "ogg", "oga", "wav", "aac", "caf", "m4a", "mp4", "weba", "webm", "dolby", "flac").
For a maximum browser coverage the recommendation is to use at least two of them, typically default to webm and then fallback to mp3 for the best balance of small filesize and high quality, webm has nearly full browser coverage with a great combination of compression and quality, and mp3 will fallback gracefully for other browsers. It is important to remember that melonJS selects the first compatible sound based on the list of extensions and given order passed here. So if you want webm to be used before mp3, you need to put the audio format in that order.
Parameters:
Name Type Argument Default Description
audioFormat String <optional>
"mp3" audio format provided
Source:
audio.js, line 67
Returns:
Indicates whether audio initialization was successful
Type
Boolean
Example
// initialize the "sound engine", giving "webm" as default desired audio format, and "mp3" as a fallback
if (!me.audio.init("webm,mp3")) {
    alert("Sorry but your browser does not support html 5 audio !");
    return;
}

<static> mute(sound_name, id, mute)

mute or unmute the specified sound, but does not pause the playback.
Parameters:
Name Type Argument Default Description
sound_name String audio clip name - case sensitive
id Number <optional>
the sound instance ID. If none is passed, all sounds in group will mute.
mute Boolean <optional>
true True to mute and false to unmute
Source:
audio.js, line 471
Example
// mute the background music
me.audio.mute("awesome_music");

<static> muteAll()

mute all audio
Source:
audio.js, line 508

<static> muted() → {Boolean}

Returns true if audio is muted globally.
Source:
audio.js, line 530
Returns:
true if audio is muted globally
Type
Boolean

<static> pause(sound_name, id)

pause the specified sound on all channels
this function does not reset the currentTime property
Parameters:
Name Type Argument Description
sound_name String audio clip name - case sensitive
id Number <optional>
the sound instance ID. If none is passed, all sounds in group will pause.
Source:
audio.js, line 305
Example
me.audio.pause("cling");

<static> pauseTrack()

pause the current audio track
Source:
audio.js, line 398
Example
me.audio.pauseTrack();

<static> play(sound_name, loop, onend, volume) → {Number}

play the specified sound
Parameters:
Name Type Argument Default Description
sound_name String audio clip name - case sensitive
loop Boolean <optional>
false loop audio
onend function <optional>
Function to call when sound instance ends playing.
volume Number <optional>
default Float specifying volume (0.0 - 1.0 values accepted).
Source:
audio.js, line 168
Returns:
the sound instance ID.
Type
Number
Example
// play the "cling" audio clip
me.audio.play("cling");
// play & repeat the "engine" audio clip
me.audio.play("engine", true);
// play the "gameover_sfx" audio clip and call myFunc when finished
me.audio.play("gameover_sfx", false, myFunc);
// play the "gameover_sfx" audio clip with a lower volume level
me.audio.play("gameover_sfx", false, null, 0.5);

<static> playTrack(sound_name, volume) → {Number}

play the specified audio track
this function automatically set the loop property to true
and keep track of the current sound being played.
Parameters:
Name Type Argument Default Description
sound_name String audio track name - case sensitive
volume Number <optional>
default Float specifying volume (0.0 - 1.0 values accepted).
Source:
audio.js, line 353
Returns:
the sound instance ID.
Type
Number
Example
me.audio.playTrack("awesome_music");

<static> rate(sound_name, rate, id)

get or set the rate of playback for a sound.
Parameters:
Name Type Argument Description
sound_name String audio clip name - case sensitive
rate Number <optional>
playback rate : 0.5 to 4.0, with 1.0 being normal speed.
id Number <optional>
the sound instance ID. If none is passed, all sounds in group will be changed.
Source:
audio.js, line 258
Returns:
return the current playback rate (if no extra parameters were given)
Example
// get the playback rate of the background music
var rate = me.audio.rate("dst-gameforest");
// speed up the playback of the background music
me.audio.rate("dst-gameforest", 2.0);

<static> resume(sound_name, id)

resume the specified sound on all channels
Parameters:
Name Type Argument Description
sound_name String audio clip name - case sensitive
id Number <optional>
the sound instance ID. If none is passed, all sounds in group will resume.
Source:
audio.js, line 326
Example
// play a audio clip
var id = me.audio.play("myClip");
...
// pause it
me.audio.pause("myClip", id);
...
// resume
me.audio.resume("myClip", id);

<static> resumeTrack()

resume the previously paused audio track
Source:
audio.js, line 414
Example
// play an awesome music
me.audio.playTrack("awesome_music");
// pause the audio track
me.audio.pauseTrack();
// resume the music
me.audio.resumeTrack();

<static> seek(sound_name, seek, id)

get/set the position of playback for a sound.
Parameters:
Name Type Argument Description
sound_name String audio clip name - case sensitive
seek Number <optional>
The position to move current playback to (in seconds).
id Number <optional>
the sound instance ID. If none is passed, all sounds in group will changed.
Source:
audio.js, line 233
Returns:
return the current seek position (if no extra parameters were given)
Example
// return the current position of the background music
var current_pos = me.audio.seek("dst-gameforest");
// set back the position of the background music to the beginning
me.audio.seek("dst-gameforest", 0);

<static> setVolume(volume)

set the default global volume
Parameters:
Name Type Description
volume Number Float specifying volume (0.0 - 1.0 values accepted).
Source:
audio.js, line 447

<static> stop(sound_name, id)

stop the specified sound on all channels
Parameters:
Name Type Argument Description
sound_name String audio clip name - case sensitive
id Number <optional>
the sound instance ID. If none is passed, all sounds in group will stop.
Source:
audio.js, line 283
Example
me.audio.stop("cling");

<static> stopTrack()

stop the current audio track
Source:
audio.js, line 377
See:
  • me.audio#playTrack
Example
// play a awesome music
me.audio.playTrack("awesome_music");
// stop the current music
me.audio.stopTrack();

<static> unload(sound_name) → {Boolean}

unload specified audio track to free memory
Parameters:
Name Type Description
sound_name String audio track name - case sensitive
Source:
audio.js, line 542
Returns:
true if unloaded
Type
Boolean
Example
me.audio.unload("awesome_music");

<static> unloadAll()

unload all audio to free memory
Source:
audio.js, line 570
Example
me.audio.unloadAll();

<static> unmute(sound_name, id)

unmute the specified sound
Parameters:
Name Type Argument Description
sound_name String audio clip name
id Number <optional>
the sound instance ID. If none is passed, all sounds in group will unmute.
Source:
audio.js, line 495

<static> unmuteAll()

unmute all audio
Source:
audio.js, line 519