cocos2d-x  3.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AudioEngine Class Reference

#include <AudioEngine.h>

Classes

struct  AudioInfo
 
struct  ProfileHelper
 

Public Types

enum  AudioState { ERROR = -1, INITIALZING, PLAYING, PAUSED }
 

Static Public Member Functions

static bool lazyInit ()
var lazyInit ()
local lazyInit ()
static void end ()
 Release related objects. More...
 
local end ()
 Release related objects. More...
 
static AudioProfilegetDefaultProfile ()
 Gets the default profile of audio instances. More...
 
var getDefaultProfile ()
 Gets the default profile of audio instances. More...
 
local getDefaultProfile ()
 Gets the default profile of audio instances. More...
 
static int play2d (const std::string &filePath, bool loop=false, float volume=1.0f, const AudioProfile *profile=nullptr)
 Play 2d sound. More...
 
local play2d ( local filePath, local false, local 0f, local nullptr)
 Play 2d sound. More...
 
static void setLoop (int audioID, bool loop)
 Sets whether an audio instance loop or not. More...
 
static bool isLoop (int audioID)
 Checks whether an audio instance is loop. More...
 
static void setVolume (int audioID, float volume)
 Sets volume for an audio instance. More...
 
local setVolume ( local audioID, local volume)
 Sets volume for an audio instance. More...
 
static float getVolume (int audioID)
 Gets the volume value of an audio instance. More...
 
static void pause (int audioID)
 Pause an audio instance. More...
 
local pause ( local audioID)
 Pause an audio instance. More...
 
static void pauseAll ()
 Pause all playing audio instances. More...
 
static void resume (int audioID)
 Resume an audio instance. More...
 
var resume ( var audioID)
 Resume an audio instance. More...
 
local resume ( local audioID)
 Resume an audio instance. More...
 
static void resumeAll ()
 Resume all suspended audio instances. More...
 
static void stop (int audioID)
 Stop an audio instance. More...
 
local stop ( local audioID)
 Stop an audio instance. More...
 
static void stopAll ()
 Stop all audio instances. More...
 
static bool setCurrentTime (int audioID, float time)
 Sets the current playback position of an audio instance. More...
 
local setCurrentTime ( local audioID, local time)
 Sets the current playback position of an audio instance. More...
 
static float getCurrentTime (int audioID)
 Gets the current playback position of an audio instance. More...
 
static float getDuration (int audioID)
 Gets the duration of an audio instance. More...
 
static AudioState getState (int audioID)
 Returns the state of an audio instance. More...
 
local getState ( local audioID)
 Returns the state of an audio instance. More...
 
static void setFinishCallback (int audioID, const std::function< void(int, const std::string &)> &callback)
 Register a callback to be invoked when an audio instance has completed playing. More...
 
static int getMaxAudioInstance ()
static bool setMaxAudioInstance (int maxInstances)
local setMaxAudioInstance ( local maxInstances)
static void uncache (const std::string &filePath)
 Uncache the audio data from internal buffer. More...
 
var uncache ( var filePath)
 Uncache the audio data from internal buffer. More...
 
local uncache ( local filePath)
 Uncache the audio data from internal buffer. More...
 
static void uncacheAll ()
 Uncache all audio data from internal buffer. More...
 
static AudioProfilegetProfile (int audioID)
 Gets the audio profile by id of audio instance. More...
 
var getProfile ( var audioID)
 Gets the audio profile by id of audio instance. More...
 
local getProfile ( local audioID)
 Gets the audio profile by id of audio instance. More...
 
static AudioProfilegetProfile (const std::string &name)
 Gets the audio profile by name. More...
 

Static Public Attributes

static const int INVALID_AUDIO_ID
var INVALID_AUDIO_ID
local INVALID_AUDIO_ID
static const float TIME_UNKNOWN

Static Protected Member Functions

static void remove (int audioID)

Static Protected Attributes

static std::unordered_map< int,
AudioInfo
_audioIDInfoMap
static std::unordered_map
< std::string, std::list< int > > 
_audioPathIDMap
static std::unordered_map
< std::string, ProfileHelper
_audioPathProfileHelperMap
static unsigned int _maxInstances
static ProfileHelper_defaultProfileHelper
var _defaultProfileHelper
local _defaultProfileHelper
static AudioEngineImpl_audioEngineImpl
var _audioEngineImpl
local _audioEngineImpl

Friends

class AudioEngineImpl

Detailed Description

Note

Member Enumeration Documentation

enum AudioState
strong
Enumerator
ERROR 
INITIALZING 
PLAYING 
PAUSED 
var AudioState
strong
Enumerator
ERROR 
INITIALZING 
PLAYING 
PAUSED 
local AudioState
strong
Enumerator
ERROR 
INITIALZING 
PLAYING 
PAUSED 

Member Function Documentation

static void end ( )
static

Release related objects.

Warning
It must be called before the application exit
var end ( )
static

Release related objects.

Warning
It must be called before the application exit
local end ( )
static

Release related objects.

Warning
It must be called before the application exit
static float getCurrentTime ( int  audioID)
static

Gets the current playback position of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the current playback position of an audio instance
var getCurrentTime ( var  audioID)
static

Gets the current playback position of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the current playback position of an audio instance
local getCurrentTime ( local  audioID)
static

Gets the current playback position of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the current playback position of an audio instance
static AudioProfile*
getDefaultProfile
( )
static

Gets the default profile of audio instances.

Returns
the default profile of audio instances
var getDefaultProfile ( )
static

Gets the default profile of audio instances.

Returns
the default profile of audio instances
local getDefaultProfile ( )
static

Gets the default profile of audio instances.

Returns
the default profile of audio instances
static float getDuration ( int  audioID)
static

Gets the duration of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the duration of an audio instance
var getDuration ( var  audioID)
static

Gets the duration of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the duration of an audio instance
local getDuration ( local  audioID)
static

Gets the duration of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the duration of an audio instance
static int getMaxAudioInstance ( )
inlinestatic
var getMaxAudioInstance ( )
inlinestatic
local getMaxAudioInstance ( )
inlinestatic
static AudioProfile* getProfile ( int  audioID)
static

Gets the audio profile by id of audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the audio profile
var getProfile ( var  audioID)
static

Gets the audio profile by id of audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the audio profile
local getProfile ( local  audioID)
static

Gets the audio profile by id of audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the audio profile
static AudioProfile* getProfile ( const std::string &  name)
static

Gets the audio profile by name.

Parameters
namename of audio profile
Returns
the audio profile
var getProfile ( var  name)
static

Gets the audio profile by name.

Parameters
namename of audio profile
Returns
the audio profile
local getProfile ( local  name)
static

Gets the audio profile by name.

Parameters
namename of audio profile
Returns
the audio profile
static AudioState getState ( int  audioID)
static

Returns the state of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the status of an audio instance
var getState ( var  audioID)
static

Returns the state of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the status of an audio instance
local getState ( local  audioID)
static

Returns the state of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
the status of an audio instance
static float getVolume ( int  audioID)
static

Gets the volume value of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
volume value (range from 0.0 to 1.0)
var getVolume ( var  audioID)
static

Gets the volume value of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
volume value (range from 0.0 to 1.0)
local getVolume ( local  audioID)
static

Gets the volume value of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
volume value (range from 0.0 to 1.0)
static bool isLoop ( int  audioID)
static

Checks whether an audio instance is loop.

Parameters
audioIDan audioID returned by the play2d function
Returns
Whether or not an audio instance is loop.
var isLoop ( var  audioID)
static

Checks whether an audio instance is loop.

Parameters
audioIDan audioID returned by the play2d function
Returns
Whether or not an audio instance is loop.
local isLoop ( local  audioID)
static

Checks whether an audio instance is loop.

Parameters
audioIDan audioID returned by the play2d function
Returns
Whether or not an audio instance is loop.
static bool lazyInit ( )
static
var lazyInit ( )
static
local lazyInit ( )
static
static void pause ( int  audioID)
static

Pause an audio instance.

Parameters
audioIDan audioID returned by the play2d function
var pause ( var  audioID)
static

Pause an audio instance.

Parameters
audioIDan audioID returned by the play2d function
local pause ( local  audioID)
static

Pause an audio instance.

Parameters
audioIDan audioID returned by the play2d function
static void pauseAll ( )
static

Pause all playing audio instances.

var pauseAll ( )
static

Pause all playing audio instances.

local pauseAll ( )
static

Pause all playing audio instances.

static int play2d ( const std::string &  filePath,
bool  loop = false,
float  volume = 1.0f,
const AudioProfile profile = nullptr 
)
static

Play 2d sound.

Parameters
filePathThe path of an audio file
loopWhether audio instance loop or not
volumevolume value (range from 0.0 to 1.0)
profilea profile for audio instance
Returns
an audio ID. It allows you to dynamically change the behavior of an audio instance on the fly.
var play2d ( var  filePath,
var  loop = false,
var  volume = 1.0f,
var  profile = nullptr 
)
static

Play 2d sound.

Parameters
filePathThe path of an audio file
loopWhether audio instance loop or not
volumevolume value (range from 0.0 to 1.0)
profilea profile for audio instance
Returns
an audio ID. It allows you to dynamically change the behavior of an audio instance on the fly.
local play2d ( local  filePath,
local  loop = false,
local  volume = 1.0f,
local  profile = nullptr 
)
static

Play 2d sound.

Parameters
filePathThe path of an audio file
loopWhether audio instance loop or not
volumevolume value (range from 0.0 to 1.0)
profilea profile for audio instance
Returns
an audio ID. It allows you to dynamically change the behavior of an audio instance on the fly.
static void remove ( int  audioID)
staticprotected
var remove ( var  audioID)
staticprotected
local remove ( local  audioID)
staticprotected
static void resume ( int  audioID)
static

Resume an audio instance.

Parameters
audioIDan audioID returned by the play2d function
var resume ( var  audioID)
static

Resume an audio instance.

Parameters
audioIDan audioID returned by the play2d function
local resume ( local  audioID)
static

Resume an audio instance.

Parameters
audioIDan audioID returned by the play2d function
static void resumeAll ( )
static

Resume all suspended audio instances.

var resumeAll ( )
static

Resume all suspended audio instances.

local resumeAll ( )
static

Resume all suspended audio instances.

static bool setCurrentTime ( int  audioID,
float  time 
)
static

Sets the current playback position of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
var setCurrentTime ( var  audioID,
var  time 
)
static

Sets the current playback position of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
local setCurrentTime ( local  audioID,
local  time 
)
static

Sets the current playback position of an audio instance.

Parameters
audioIDan audioID returned by the play2d function
Returns
static void setFinishCallback ( int  audioID,
const std::function< void(int, const std::string &)> &  callback 
)
static

Register a callback to be invoked when an audio instance has completed playing.

Parameters
audioIDan audioID returned by the play2d function
callback
var setFinishCallback ( var  audioID,
var  callback 
)
static

Register a callback to be invoked when an audio instance has completed playing.

Parameters
audioIDan audioID returned by the play2d function
callback
local setFinishCallback ( local  audioID,
local  callback 
)
static

Register a callback to be invoked when an audio instance has completed playing.

Parameters
audioIDan audioID returned by the play2d function
callback
static void setLoop ( int  audioID,
bool  loop 
)
static

Sets whether an audio instance loop or not.

Parameters
audioIDan audioID returned by the play2d function
loopWhether audio instance loop or not
var setLoop ( var  audioID,
var  loop 
)
static

Sets whether an audio instance loop or not.

Parameters
audioIDan audioID returned by the play2d function
loopWhether audio instance loop or not
local setLoop ( local  audioID,
local  loop 
)
static

Sets whether an audio instance loop or not.

Parameters
audioIDan audioID returned by the play2d function
loopWhether audio instance loop or not
static bool setMaxAudioInstance ( int  maxInstances)
static
var setMaxAudioInstance ( var  maxInstances)
static
local setMaxAudioInstance ( local  maxInstances)
static
static void setVolume ( int  audioID,
float  volume 
)
static

Sets volume for an audio instance.

Parameters
audioIDan audioID returned by the play2d function
volumevolume value (range from 0.0 to 1.0)
var setVolume ( var  audioID,
var  volume 
)
static

Sets volume for an audio instance.

Parameters
audioIDan audioID returned by the play2d function
volumevolume value (range from 0.0 to 1.0)
local setVolume ( local  audioID,
local  volume 
)
static

Sets volume for an audio instance.

Parameters
audioIDan audioID returned by the play2d function
volumevolume value (range from 0.0 to 1.0)
static void stop ( int  audioID)
static

Stop an audio instance.

Parameters
audioIDan audioID returned by the play2d function
var stop ( var  audioID)
static

Stop an audio instance.

Parameters
audioIDan audioID returned by the play2d function
local stop ( local  audioID)
static

Stop an audio instance.

Parameters
audioIDan audioID returned by the play2d function
static void stopAll ( )
static

Stop all audio instances.

var stopAll ( )
static

Stop all audio instances.

local stopAll ( )
static

Stop all audio instances.

static void uncache ( const std::string &  filePath)
static

Uncache the audio data from internal buffer.

AudioEngine cache audio data on ios platform

Warning
This can lead to stop related audio first.
Parameters
filePathThe path of an audio file
var uncache ( var  filePath)
static

Uncache the audio data from internal buffer.

AudioEngine cache audio data on ios platform

Warning
This can lead to stop related audio first.
Parameters
filePathThe path of an audio file
local uncache ( local  filePath)
static

Uncache the audio data from internal buffer.

AudioEngine cache audio data on ios platform

Warning
This can lead to stop related audio first.
Parameters
filePathThe path of an audio file
static void uncacheAll ( )
static

Uncache all audio data from internal buffer.

Warning
All audio will be stopped first.
Parameters
var uncacheAll ( )
static

Uncache all audio data from internal buffer.

Warning
All audio will be stopped first.
Parameters
local uncacheAll ( )
static

Uncache all audio data from internal buffer.

Warning
All audio will be stopped first.
Parameters

Friends And Related Function Documentation

friend class AudioEngineImpl
friend
var AudioEngineImpl
friend
local AudioEngineImpl
friend

Member Data Documentation

AudioEngineImpl* _audioEngineImpl
staticprotected
var _audioEngineImpl
staticprotected
local _audioEngineImpl
staticprotected
std::unordered_map<int,
AudioInfo> _audioIDInfoMap
staticprotected
var _audioIDInfoMap
staticprotected
local _audioIDInfoMap
staticprotected
std::unordered_map<std::string,std::list
<int> > _audioPathIDMap
staticprotected
var _audioPathIDMap
staticprotected
local _audioPathIDMap
staticprotected
std::unordered_map<std::string,
ProfileHelper>
_audioPathProfileHelperMap
staticprotected
var _audioPathProfileHelperMap
staticprotected
local _audioPathProfileHelperMap
staticprotected
ProfileHelper*
_defaultProfileHelper
staticprotected
var _defaultProfileHelper
staticprotected
local _defaultProfileHelper
staticprotected
unsigned int _maxInstances
staticprotected
var _maxInstances
staticprotected
local _maxInstances
staticprotected
const int INVALID_AUDIO_ID
static
var INVALID_AUDIO_ID
static
local INVALID_AUDIO_ID
static
const float TIME_UNKNOWN
static
var TIME_UNKNOWN
static
local TIME_UNKNOWN
static

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