Play background music
Cc.audioEngine.playMusic (URL , Loop ); @param {String} url sound path @param {Boolean} loop whether to loop playback
Stop Background musicCc.audioengine.Stopmusic(Releasedata); * @param {Boolean} releasedata whether to release sound data, default to False
Pause background Music
Cc.audioengine.Pausemusic ();
Restore background music
Cc.audioengine.Resumemusic();
re-play background musicCc.audioengine.Rewindmusic ();
Get background music volumeCc.audioengine.Getmusicvolume();
* @return {number}Values from 0 to 1.0
Set background music volumeCc.audioengine.Setmusicvolume(Volume);
* @param {number} volume range 0.0~1.0 .
gets whether the background music is in playCc.audioengine.ismusicplaying();
* @return {Boolean} is playing back true, otherwise returns false
Play sound (basically similar to music) Cc.audioengine.Playeffect( URL , Loop ); * @param {String} URL Audio file path * @param {Boolean} loop whether to loop playback, the default value is False * @return {number|null} return Sound IDaudioid Cc.audioengine.Geteffectsvolume ();//Get Sound volume
Cc.audioengine.Seteffectsvolume (volume);//Set Sound volume
Cc.audioengine.Pauseeffect (audioid);//Pause the corresponding soundCc.audioengine.pausealleffects();//Pause all sound effects
Cc.audioengine. Resumeeffect(audioid);//restore the corresponding soundCc.audioengine. resumealleffects();//restore all sound effects
Cc.audioengine. Stopeffect(audioid);//Stop the corresponding sound
Cc.audioengine. Unloadeffect(URL);//unload sound data in memory buffers
stop playing all music and sound effects filescc.audioEngine.end ();Supported platforms and formats(form from official documents)
The music formats supported by Cocosdesion are as follows:
Platform |
common file formats supported |
Notes |
Android |
MP3, Mid, OGGG, WAV |
All formats supported by Android.media.MediaPlayer can be played |
Ios |
AAC, CAF, MP3, M4A, wav |
All formats supported by Avaudioplayer can be played |
Windows |
Mid, MP3, WAV |
No |
The audio formats supported by Cocosdesion are as follows:
Platform |
common file formats supported |
Notes |
Android |
OGGG, WAV |
Support for WAV is not perfect |
Ios |
CAF, M4A |
All formats supported by Cocos2d-iphone Cocosdesion can be played |
Windows |
Mid, WAV |
No |
cocos2d-js3.1--Sound