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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:92
Parameters
  • filePath String The path of the audio file without filename extension.
  • loop Boolean Whether the music loop or not.
  • volume Number Volume size.
Examples
var audioID = cc.audioEngine.play(path, false, 0.5);
setLoop

Set audio loop.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:125
Parameters
Examples
cc.audioEngine.setLoop(id, true);
isLoop

Get audio cycle state.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:141
Parameters
Examples
cc.audioEngine.isLoop(id);
setVolume

Set the volume of audio.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:157
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:179
Parameters
Examples
var volume = cc.audioEngine.getVolume(id);
setCurrentTime

Set current time

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:195
Parameters
Examples
cc.audioEngine.setCurrentTime(id, 2);
getCurrentTime

Get current time

meta description
Returns Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:220
Parameters
Examples
var time = cc.audioEngine.getCurrentTime(id);
getDuration

Get audio duration

meta description
Returns Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:236
Parameters
Examples
var time = cc.audioEngine.getDuration(id);
getState

Get audio state

meta description
Returns audioEngine.AudioState
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:252
Parameters
Examples
var state = cc.audioEngine.getState(id);
setFinishCallback

Set Audio finish callback

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:268
Parameters
Examples
cc.audioEngine.setFinishCallback(id, function () {});
pause

Pause playing audio.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:287
Parameters
  • audioID Number The return value of function play.
Examples
cc.audioEngine.pause(audioID);
pauseAll

Pause all playing audio

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:304
Examples
cc.audioEngine.pauseAll();
resume

Resume playing audio.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:322
Parameters
  • audioID Number The return value of function play.
Examples
cc.audioEngine.resume(audioID);
resumeAll

Resume all playing audio.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:341
Examples
cc.audioEngine.resumeAll();
stop

Stop playing audio.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:357
Parameters
  • audioID Number The return value of function play.
Examples
cc.audioEngine.stop(audioID);
stopAll

Stop all playing audio.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:374
Examples
cc.audioEngine.stopAll();
setMaxAudioInstance

Set up an audio can generate a few examples.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:391
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:403
Examples
cc.audioEngine.getMaxAudioInstance();
uncache

Unload the preloaded audio from internal buffer.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:415
Parameters
Examples
cc.audioEngine.uncache(filePath);
uncacheAll

Unload all audio from internal buffer.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:436
Examples
cc.audioEngine.uncacheAll();
preload

Preload audio file.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:457
Parameters
  • filePath String The file path of an audio.
  • callback Function The callback of an audio.
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/audio/CCAudioEngine.js:474
Parameters
  • kb Number The file path of an audio.
Examples
cc.audioEngine.setMaxWebAudioSize(300);

results matching ""

    No results matching ""