audioEngine Class

Module: cc

cc.audioEngine is the singleton object, it provide simple audio APIs.

Index

Methods

Details

Methods

play

Play audio.

meta description
Returns Number
Defined in cocos2d/audio/CCAudioEngine.js:143
Parameters
  • clip AudioClip The audio clip to play.
  • loop Boolean Whether the music loop or not.
  • volume Number Volume size.
Examples
cc.resources.load(path, cc.AudioClip, null, function (err, clip) {
    var audioID = cc.audioEngine.play(clip, false, 0.5);
});
setLoop

Set audio loop.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:175
Parameters
Examples
cc.audioEngine.setLoop(id, true);
isLoop

Get audio cycle state.

meta description
Returns Boolean
Defined in cocos2d/audio/CCAudioEngine.js:191
Parameters
Examples
cc.audioEngine.isLoop(id);
setVolume

Set the volume of audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:207
Parameters
  • audioID Number audio id.
  • volume Number Volume must be in 0.0~1.0 .
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:223
Parameters
Examples
var volume = cc.audioEngine.getVolume(id);
setCurrentTime

Set current time

meta description
Returns Boolean
Defined in cocos2d/audio/CCAudioEngine.js:237
Parameters
Examples
cc.audioEngine.setCurrentTime(id, 2);
getCurrentTime

Get current time

meta description
Returns Number
Defined in cocos2d/audio/CCAudioEngine.js:258
Parameters
Examples
var time = cc.audioEngine.getCurrentTime(id);
getDuration

Get audio duration

meta description
Returns Number
Defined in cocos2d/audio/CCAudioEngine.js:272
Parameters
Examples
var time = cc.audioEngine.getDuration(id);
getState

Get audio state

meta description
Returns audioEngine.AudioState
Defined in cocos2d/audio/CCAudioEngine.js:286
Parameters
Examples
var state = cc.audioEngine.getState(id);
isPlaying

Whether the audio is playing

meta description
Returns Boolean
Defined in cocos2d/audio/CCAudioEngine.js:300
Examples
cc.audioEngine.isPlaying(audioID);
setFinishCallback

Set Audio finish callback

meta description
Defined in cocos2d/audio/CCAudioEngine.js:312
Parameters
Examples
cc.audioEngine.setFinishCallback(id, function () {});
pause

Pause playing audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:328
Parameters
  • audioID Number The return value of function play.
Examples
cc.audioEngine.pause(audioID);
pauseAll

Pause all playing audio

meta description
Defined in cocos2d/audio/CCAudioEngine.js:348
Examples
cc.audioEngine.pauseAll();
resume

Resume playing audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:366
Parameters
  • audioID Number The return value of function play.
Examples
cc.audioEngine.resume(audioID);
resumeAll

Resume all playing audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:381
Examples
cc.audioEngine.resumeAll();
stop

Stop playing audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:398
Parameters
  • audioID Number The return value of function play.
Examples
cc.audioEngine.stop(audioID);
stopAll

Stop all playing audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:418
Examples
cc.audioEngine.stopAll();
setMaxAudioInstance

Set up an audio can generate a few examples.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:435
Deprecated since v2.4.0
Parameters
  • num Number 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:451
Examples
cc.audioEngine.getMaxAudioInstance();
uncache

Unload the preloaded audio from internal buffer.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:463
Parameters
Examples
cc.audioEngine.uncache(filePath);
uncacheAll

Unload all audio from internal buffer.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:498
Examples
cc.audioEngine.uncacheAll();
playMusic

Play background music

meta description
Returns Number
Defined in cocos2d/audio/CCAudioEngine.js:560
Parameters
  • clip AudioClip The audio clip to play.
  • loop Boolean Whether the music loop or not.
Examples
cc.resources.load(path, cc.AudioClip, null, function (err, clip) {
    var audioID = cc.audioEngine.playMusic(clip, false);
});
stopMusic

Stop background music.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:580
Examples
cc.audioEngine.stopMusic();
pauseMusic

Pause the background music.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:591
Examples
cc.audioEngine.pauseMusic();
resumeMusic

Resume playing background music.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:603
Examples
cc.audioEngine.resumeMusic();
getMusicVolume

Get the volume(0.0 ~ 1.0).

meta description
Returns Number
Defined in cocos2d/audio/CCAudioEngine.js:615
Examples
var volume = cc.audioEngine.getMusicVolume();
setMusicVolume

Set the background music volume.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:627
Parameters
  • volume Number 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:643
Examples
cc.audioEngine.isMusicPlaying();
playEffect

Play effect audio.

meta description
Returns Number
Defined in cocos2d/audio/CCAudioEngine.js:655
Parameters
  • clip AudioClip The audio clip to play.
  • loop Boolean Whether the music loop or not.
Examples
cc.resources.load(path, cc.AudioClip, null, 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:671
Parameters
  • volume Number 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:690
Examples
var volume = cc.audioEngine.getEffectsVolume();
pauseEffect

Pause effect audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:702
Parameters
Examples
cc.audioEngine.pauseEffect(audioID);
pauseAllEffects

Stop playing all the sound effects.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:714
Examples
cc.audioEngine.pauseAllEffects();
resumeEffect

Resume effect audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:737
Parameters
  • audioID Number The return value of function play.
Examples
cc.audioEngine.resumeEffect(audioID);
resumeAllEffects

Resume all effect audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:749
Examples
cc.audioEngine.resumeAllEffects();
stopEffect

Stop playing the effect audio.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:766
Parameters
Examples
cc.audioEngine.stopEffect(id);
stopAllEffects

Stop playing all the effects.

meta description
Defined in cocos2d/audio/CCAudioEngine.js:778
Examples
cc.audioEngine.stopAllEffects();

results matching ""

    No results matching ""