audioEngine Class
Module: cc
cc.audioEngine is the singleton object, it provide simple audio APIs.
Index
Methods
- playPlay audio.
- setLoopSet audio loop.
- isLoopGet audio cycle state.
- setVolumeSet the volume of audio.
- getVolumeThe volume of the music max value is 1.0,the min value is 0.0 .
- setCurrentTimeSet current time
- getCurrentTimeGet current time
- getDurationGet audio duration
- getStateGet audio state
- setFinishCallbackSet Audio finish callback
- pausePause playing audio.
- pauseAllPause all playing audio
- resumeResume playing audio.
- resumeAllResume all playing audio.
- stopStop playing audio.
- stopAllStop all playing audio.
- setMaxAudioInstanceSet up an audio can generate a few examples.
- getMaxAudioInstanceGetting audio can produce several examples.
- uncacheUnload the preloaded audio from internal buffer.
- uncacheAllUnload all audio from internal buffer.
- preloadPreload audio file.
- setMaxWebAudioSizeSet a size, the unit is KB.
- playMusicPlay background music
- stopMusicStop background music.
- pauseMusicPause the background music.
- resumeMusicResume playing background music.
- getMusicVolumeGet the volume(0.0 ~ 1.0).
- setMusicVolumeSet the background music volume.
- isMusicPlayingBackground music playing state
- playEffectPlay effect audio.
- setEffectsVolumeSet the volume of effect audio.
- getEffectsVolumeThe volume of the effect audio max value is 1.0,the min value is 0.0 .
- pauseEffectPause effect audio.
- pauseAllEffectsStop playing all the sound effects.
- resumeEffectResume effect audio.
- resumeAllEffectsResume all effect audio.
- stopEffectStop playing the effect audio.
- stopAllEffectsStop playing all the effects.
Details
Methods
play
Play audio.
| meta | description | 
|---|---|
| Returns | Number | 
| Defined in | cocos2d/audio/CCAudioEngine.js:93 | 
Parameters
- clipAudioClip The audio clip to play.
- loopBoolean Whether the music loop or not.
- volumeNumber Volume size.
Examples
cc.loader.loadRes(url, cc.AudioClip, function (err, clip) {
    var audioID = cc.audioEngine.play(clip, false, 0.5);
});
setLoop
Set audio loop.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:140 | 
Parameters
Examples
cc.audioEngine.setLoop(id, true);
isLoop
Get audio cycle state.
| meta | description | 
|---|---|
| Returns | Boolean | 
| Defined in | cocos2d/audio/CCAudioEngine.js:156 | 
Parameters
- audioIDNumber audio id.
Examples
cc.audioEngine.isLoop(id);
setVolume
Set the volume of audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:172 | 
Parameters
Examples
cc.audioEngine.setVolume(id, 0.5);
getVolume
The volume of the music max value is 1.0,the min value is 0.0 .
| meta | description | 
|---|---|
| Returns | Number | 
| Defined in | cocos2d/audio/CCAudioEngine.js:188 | 
Parameters
- audioIDNumber audio id.
Examples
var volume = cc.audioEngine.getVolume(id);
setCurrentTime
Set current time
| meta | description | 
|---|---|
| Returns | Boolean | 
| Defined in | cocos2d/audio/CCAudioEngine.js:202 | 
Parameters
Examples
cc.audioEngine.setCurrentTime(id, 2);
getCurrentTime
Get current time
| meta | description | 
|---|---|
| Returns | Number | 
| Defined in | cocos2d/audio/CCAudioEngine.js:223 | 
Parameters
- audioIDNumber audio id.
Examples
var time = cc.audioEngine.getCurrentTime(id);
getDuration
Get audio duration
| meta | description | 
|---|---|
| Returns | Number | 
| Defined in | cocos2d/audio/CCAudioEngine.js:237 | 
Parameters
- audioIDNumber audio id.
Examples
var time = cc.audioEngine.getDuration(id);
getState
Get audio state
| meta | description | 
|---|---|
| Returns | audioEngine.AudioState | 
| Defined in | cocos2d/audio/CCAudioEngine.js:251 | 
Parameters
- audioIDNumber audio id.
Examples
var state = cc.audioEngine.getState(id);
setFinishCallback
Set Audio finish callback
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:265 | 
Parameters
Examples
cc.audioEngine.setFinishCallback(id, function () {});
pause
Pause playing audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:284 | 
Parameters
- audioIDNumber The return value of function play.
Examples
cc.audioEngine.pause(audioID);
pauseAll
Pause all playing audio
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:304 | 
Examples
cc.audioEngine.pauseAll();
resume
Resume playing audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:322 | 
Parameters
- audioIDNumber The return value of function play.
Examples
cc.audioEngine.resume(audioID);
resumeAll
Resume all playing audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:337 | 
Examples
cc.audioEngine.resumeAll();
stop
Stop playing audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:354 | 
Parameters
- audioIDNumber The return value of function play.
Examples
cc.audioEngine.stop(audioID);
stopAll
Stop all playing audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:374 | 
Examples
cc.audioEngine.stopAll();
setMaxAudioInstance
Set up an audio can generate a few examples.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:391 | 
Parameters
- numNumber a number of instances to be created from within an audio
Examples
cc.audioEngine.setMaxAudioInstance(20);
getMaxAudioInstance
Getting audio can produce several examples.
| meta | description | 
|---|---|
| Returns | Number | 
| Defined in | cocos2d/audio/CCAudioEngine.js:403 | 
Examples
cc.audioEngine.getMaxAudioInstance();
uncache
Unload the preloaded audio from internal buffer.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:415 | 
Parameters
- clipAudioClip
Examples
cc.audioEngine.uncache(filePath);
uncacheAll
Unload all audio from internal buffer.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:450 | 
Examples
cc.audioEngine.uncacheAll();
preload
Preload audio file.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:477 | 
| Deprecated | `cc.audioEngine.preload` is deprecated, use `cc.loader.loadRes(url, cc.AudioClip)` instead please. | 
Parameters
Examples
cc.audioEngine.preload(path);
setMaxWebAudioSize
Set a size, the unit is KB. Over this size is directly resolved into DOM nodes.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:499 | 
Parameters
- kbNumber The file path of an audio.
Examples
cc.audioEngine.setMaxWebAudioSize(300);
playMusic
Play background music
| meta | description | 
|---|---|
| Returns | Number | 
| Defined in | cocos2d/audio/CCAudioEngine.js:551 | 
Parameters
Examples
cc.loader.loadRes(url, cc.AudioClip, function (err, clip) {
    var audioID = cc.audioEngine.playMusic(clip, false);
});
stopMusic
Stop background music.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:571 | 
Examples
cc.audioEngine.stopMusic();
pauseMusic
Pause the background music.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:582 | 
Examples
cc.audioEngine.pauseMusic();
resumeMusic
Resume playing background music.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:594 | 
Examples
cc.audioEngine.resumeMusic();
getMusicVolume
Get the volume(0.0 ~ 1.0).
| meta | description | 
|---|---|
| Returns | Number | 
| Defined in | cocos2d/audio/CCAudioEngine.js:606 | 
Examples
var volume = cc.audioEngine.getMusicVolume();
setMusicVolume
Set the background music volume.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:618 | 
Parameters
- volumeNumber Volume must be in 0.0~1.0.
Examples
cc.audioEngine.setMusicVolume(0.5);
isMusicPlaying
Background music playing state
| meta | description | 
|---|---|
| Returns | Boolean | 
| Defined in | cocos2d/audio/CCAudioEngine.js:633 | 
Examples
cc.audioEngine.isMusicPlaying();
playEffect
Play effect audio.
| meta | description | 
|---|---|
| Returns | Number | 
| Defined in | cocos2d/audio/CCAudioEngine.js:645 | 
Parameters
Examples
cc.loader.loadRes(url, cc.AudioClip, function (err, clip) {
    var audioID = cc.audioEngine.playEffect(clip, false);
});
setEffectsVolume
Set the volume of effect audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:661 | 
Parameters
- volumeNumber Volume must be in 0.0~1.0.
Examples
cc.audioEngine.setEffectsVolume(0.5);
getEffectsVolume
The volume of the effect audio max value is 1.0,the min value is 0.0 .
| meta | description | 
|---|---|
| Returns | Number | 
| Defined in | cocos2d/audio/CCAudioEngine.js:679 | 
Examples
var volume = cc.audioEngine.getEffectsVolume();
pauseEffect
Pause effect audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:691 | 
Parameters
- audioIDNumber audio id.
Examples
cc.audioEngine.pauseEffect(audioID);
pauseAllEffects
Stop playing all the sound effects.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:703 | 
Examples
cc.audioEngine.pauseAllEffects();
resumeEffect
Resume effect audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:726 | 
Parameters
- audioIDNumber The return value of function play.
Examples
cc.audioEngine.resumeEffect(audioID);
resumeAllEffects
Resume all effect audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:738 | 
Examples
cc.audioEngine.resumeAllEffects();
stopEffect
Stop playing the effect audio.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:755 | 
Parameters
- audioIDNumber audio id.
Examples
cc.audioEngine.stopEffect(id);
stopAllEffects
Stop playing all the effects.
| meta | description | 
|---|---|
| Defined in | cocos2d/audio/CCAudioEngine.js:767 | 
Examples
cc.audioEngine.stopAllEffects();
