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 211

<static> getCurrentTrack() → {String}

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

<static> getVolume() → {Number}

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

<static> init(audioFormat) → {Boolean}

configure and initialize the audio engine
melonJS will try to load audio files corresponding to the browser supported audio format(s)
below is the list of supported file extentions :
"mp3", "mpeg", opus", "ogg", "oga", "wav", "aac", "caf", "m4a", "mp4", "weba", "webm", "dolby", "flac"
keep in mind that not all browsers can play all audio formats, and if no compatible codecs are detected, audio will be disabled.
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 "mp3" and "ogg" as desired audio format
// i.e. on Safari, the loader will load all audio.mp3 files,
// on Opera the loader will however load audio.ogg files
if (!me.audio.init("mp3,ogg")) {
    alert("Sorry but your browser does not support html 5 audio !");
    return;
}

<static> mute(sound_name, id, muted)

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.
muted Boolean <optional>
true True to mute and false to unmute
Source:
audio.js, line 470
Example
// mute the background music
me.audio.mute("awesome_music");

<static> muteAll()

mute all audio
Source:
audio.js, line 507

<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 304
Example
me.audio.pause("cling");

<static> pauseTrack()

pause the current audio track
Source:
audio.js, line 397
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 167
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 352
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 257
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 325
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 413
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 232
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 446

<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 282
Example
me.audio.stop("cling");

<static> stopTrack()

stop the current audio track
Source:
audio.js, line 376
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 529
Returns:
true if unloaded
Type
Boolean
Example
me.audio.unload("awesome_music");

<static> unloadAll()

unload all audio to free memory
Source:
audio.js, line 557
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 494

<static> unmuteAll()

unmute all audio
Source:
audio.js, line 518
Copyright © 2011 - 2017, Olivier Biot, Jason Oster, Aaron McLeod
Documentation generated by JSDoc 3.4.0 on 2017-02-28T11:37:40+08:00 using the DocStrap template modified by codename-.