Cocos2d-x  v3.17
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
SimpleAudioEngine Class Reference

Offers a very simple interface to play background music & sound effects. More...

Public Member Functions

virtual void preloadBackgroundMusic (const char *filePath)
 Preload background music. More...
 
local preloadMusic ( local filePath)
 Preload background music. More...
 
virtual void playBackgroundMusic (const char *filePath, bool loop=false)
 Play background music. More...
 
local playMusic ( local filePath, local false)
 Play background music. More...
 
virtual void stopBackgroundMusic (bool releaseData=false)
 Stop playing background music. More...
 
virtual void pauseBackgroundMusic ()
 Pause playing background music.
 
virtual void resumeBackgroundMusic ()
 Resume playing background music.
 
var resumeMusic ()
 Resume playing background music.
 
local resumeMusic ()
 Resume playing background music.
 
virtual void rewindBackgroundMusic ()
 Rewind playing background music.
 
local rewindMusic ()
 Rewind playing background music.
 
virtual bool willPlayBackgroundMusic ()
 Indicates whether any background music can be played or not. More...
 
virtual bool isBackgroundMusicPlaying ()
 Indicates whether the background music is playing. More...
 
var isMusicPlaying ()
 Indicates whether the background music is playing. More...
 
local isMusicPlaying ()
 Indicates whether the background music is playing. More...
 
virtual float getBackgroundMusicVolume ()
 The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum.
 
virtual void setBackgroundMusicVolume (float volume)
 Set the volume of background music. More...
 
var setMusicVolume ( var volume)
 Set the volume of background music. More...
 
local setMusicVolume ( local volume)
 Set the volume of background music. More...
 
virtual float getEffectsVolume ()
 The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum.
 
virtual void setEffectsVolume (float volume)
 Set the volume of sound effects. More...
 
local setEffectsVolume ( local volume)
 Set the volume of sound effects. More...
 
virtual unsigned int playEffect (const char *filePath, bool loop=false, float pitch=1.0f, float pan=0.0f, float gain=1.0f)
 Play sound effect with a file path, pitch, pan and gain. More...
 
var playEffect ( var filePath, var false, var 0f, var 0f, var 0f)
 Play sound effect with a file path, pitch, pan and gain. More...
 
local playEffect ( local filePath, local false, local 0f, local 0f, local 0f)
 Play sound effect with a file path, pitch, pan and gain. More...
 
virtual void pauseEffect (unsigned int soundId)
 Pause playing sound effect. More...
 
virtual void pauseAllEffects ()
 Pause all playing sound effect.
 
virtual void resumeEffect (unsigned int soundId)
 Resume playing sound effect. More...
 
var resumeEffect ( var soundId)
 Resume playing sound effect. More...
 
local resumeEffect ( local soundId)
 Resume playing sound effect. More...
 
virtual void resumeAllEffects ()
 Resume all playing sound effect.
 
virtual void stopEffect (unsigned int soundId)
 Stop playing sound effect. More...
 
local stopEffect ( local soundId)
 Stop playing sound effect. More...
 
virtual void stopAllEffects ()
 Stop all playing sound effects.
 
virtual void preloadEffect (const char *filePath)
 Preload a compressed audio file. More...
 
local preloadEffect ( local filePath)
 Preload a compressed audio file. More...
 
virtual void unloadEffect (const char *filePath)
 Unload the preloaded effect from internal buffer. More...
 

Static Public Member Functions

static SimpleAudioEnginegetInstance ()
 Returns a shared instance of the SimpleAudioEngine.
 
local getInstance ()
 Returns a shared instance of the SimpleAudioEngine.
 
static SimpleAudioEnginesharedEngine ()
static void end ()
 Release the shared Engine object. More...
 

Detailed Description

Offers a very simple interface to play background music & sound effects.

Note
Make sure to call SimpleAudioEngine::end() when the sound engine is not needed anymore to release allocated resources.

Member Function Documentation

static SimpleAudioEngine*
sharedEngine
( )
inlinestatic
static void end ( )
static

Release the shared Engine object.

Warning
It must be called before the application exit, or it will lead to memory leaks.
var end ( )
static

Release the shared Engine object.

Warning
It must be called before the application exit, or it will lead to memory leaks.
local destroyInstance ( )
static

Release the shared Engine object.

Warning
It must be called before the application exit, or it will lead to memory leaks.
virtual void preloadBackgroundMusic ( const char *  filePath)
virtual

Preload background music.

Parameters
filePathThe path of the background music file.
local preloadMusic ( local  filePath)
virtual

Preload background music.

Parameters
filePathThe path of the background music file.
virtual void playBackgroundMusic ( const char *  filePath,
bool  loop = false 
)
virtual

Play background music.

Parameters
filePathThe path of the background music file,or the FileName of T_SoundResInfo.
loopWhether the background music loop or not.
var playMusic ( var  filePath,
var  loop = false 
)
virtual

Play background music.

Parameters
filePathThe path of the background music file,or the FileName of T_SoundResInfo.
loopWhether the background music loop or not.
local playMusic ( local  filePath,
local  loop = false 
)
virtual

Play background music.

Parameters
filePathThe path of the background music file,or the FileName of T_SoundResInfo.
loopWhether the background music loop or not.
virtual void stopBackgroundMusic ( bool  releaseData = false)
virtual

Stop playing background music.

Parameters
releaseDataIf release the background music data or not.As default value is false.
var stopMusic ( var  releaseData = false)
virtual

Stop playing background music.

Parameters
releaseDataIf release the background music data or not.As default value is false.
local stopMusic ( local  releaseData = false)
virtual

Stop playing background music.

Parameters
releaseDataIf release the background music data or not.As default value is false.
virtual bool
willPlayBackgroundMusic
( )
virtual

Indicates whether any background music can be played or not.

Returns
true if background music can be played, otherwise false.
var willPlayMusic ( )
virtual

Indicates whether any background music can be played or not.

Returns
true if background music can be played, otherwise false.
local willPlayMusic ( )
virtual

Indicates whether any background music can be played or not.

Returns
true if background music can be played, otherwise false.
virtual bool
isBackgroundMusicPlaying
( )
virtual

Indicates whether the background music is playing.

Returns
true if the background music is playing, otherwise false.
var isMusicPlaying ( )
virtual

Indicates whether the background music is playing.

Returns
true if the background music is playing, otherwise false.
local isMusicPlaying ( )
virtual

Indicates whether the background music is playing.

Returns
true if the background music is playing, otherwise false.
virtual void
setBackgroundMusicVolume
( float  volume)
virtual

Set the volume of background music.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
var setMusicVolume ( var  volume)
virtual

Set the volume of background music.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
local setMusicVolume ( local  volume)
virtual

Set the volume of background music.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
virtual void setEffectsVolume ( float  volume)
virtual

Set the volume of sound effects.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
var setEffectsVolume ( var  volume)
virtual

Set the volume of sound effects.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
local setEffectsVolume ( local  volume)
virtual

Set the volume of sound effects.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
virtual unsigned int playEffect ( const char *  filePath,
bool  loop = false,
float  pitch = 1.0f,
float  pan = 0.0f,
float  gain = 1.0f 
)
virtual

Play sound effect with a file path, pitch, pan and gain.

Parameters
filePathThe path of the effect file.
loopDetermines whether to loop the effect playing or not. The default value is false.
pitchFrequency, normal value is 1.0. Will also change effect play time.
panStereo effect, in the range of [-1..1] where -1 enables only left channel.
gainVolume, in the range of [0..1]. The normal value is 1.
Returns
The sound id.
Note
Full support is under development, now there are limitations:
  • no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
  • no pitch/pan/gain on win32.
var playEffect ( var  filePath,
var  loop = false,
var  pitch = 1.0f,
var  pan = 0.0f,
var  gain = 1.0f 
)
virtual

Play sound effect with a file path, pitch, pan and gain.

Parameters
filePathThe path of the effect file.
loopDetermines whether to loop the effect playing or not. The default value is false.
pitchFrequency, normal value is 1.0. Will also change effect play time.
panStereo effect, in the range of [-1..1] where -1 enables only left channel.
gainVolume, in the range of [0..1]. The normal value is 1.
Returns
The sound id.
Note
Full support is under development, now there are limitations:
  • no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
  • no pitch/pan/gain on win32.
local playEffect ( local  filePath,
local  loop = false,
local  pitch = 1.0f,
local  pan = 0.0f,
local  gain = 1.0f 
)
virtual

Play sound effect with a file path, pitch, pan and gain.

Parameters
filePathThe path of the effect file.
loopDetermines whether to loop the effect playing or not. The default value is false.
pitchFrequency, normal value is 1.0. Will also change effect play time.
panStereo effect, in the range of [-1..1] where -1 enables only left channel.
gainVolume, in the range of [0..1]. The normal value is 1.
Returns
The sound id.
Note
Full support is under development, now there are limitations:
  • no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
  • no pitch/pan/gain on win32.
virtual void pauseEffect ( unsigned int  soundId)
virtual

Pause playing sound effect.

Parameters
soundIdThe return value of function playEffect.
var pauseEffect ( var  soundId)
virtual

Pause playing sound effect.

Parameters
soundIdThe return value of function playEffect.
local pauseEffect ( local  soundId)
virtual

Pause playing sound effect.

Parameters
soundIdThe return value of function playEffect.
virtual void resumeEffect ( unsigned int  soundId)
virtual

Resume playing sound effect.

Parameters
soundIdThe return value of function playEffect.
var resumeEffect ( var  soundId)
virtual

Resume playing sound effect.

Parameters
soundIdThe return value of function playEffect.
local resumeEffect ( local  soundId)
virtual

Resume playing sound effect.

Parameters
soundIdThe return value of function playEffect.
virtual void stopEffect ( unsigned int  soundId)
virtual

Stop playing sound effect.

Parameters
soundIdThe return value of function playEffect.
var stopEffect ( var  soundId)
virtual

Stop playing sound effect.

Parameters
soundIdThe return value of function playEffect.
local stopEffect ( local  soundId)
virtual

Stop playing sound effect.

Parameters
soundIdThe return value of function playEffect.
virtual void preloadEffect ( const char *  filePath)
virtual

Preload a compressed audio file.

The compressed audio will be decoded to wave, then written into an internal buffer in SimpleAudioEngine.

Parameters
filePathThe path of the effect file.
local preloadEffect ( local  filePath)
virtual

Preload a compressed audio file.

The compressed audio will be decoded to wave, then written into an internal buffer in SimpleAudioEngine.

Parameters
filePathThe path of the effect file.
virtual void unloadEffect ( const char *  filePath)
virtual

Unload the preloaded effect from internal buffer.

Parameters
filePathThe path of the effect file.
var unloadEffect ( var  filePath)
virtual

Unload the preloaded effect from internal buffer.

Parameters
filePathThe path of the effect file.
local unloadEffect ( local  filePath)
virtual

Unload the preloaded effect from internal buffer.

Parameters
filePathThe path of the effect file.

The documentation for this class was generated from the following file: