cocos2d-x  3.3
 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 ()
 
static void end ()
 Release related objects. More...
 
static AudioProfilegetDefaultProfile ()
 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...
 
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...
 
static float getVolume (int audioID)
 Gets the volume value of an audio instance. More...
 
static void pause (int 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...
 
static void resumeAll ()
 Resume all suspended audio instances. More...
 
static void stop (int 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...
 
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...
 
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)
 
static void uncache (const std::string &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...
 
static AudioProfilegetProfile (const std::string &name)
 Gets the audio profile by name. More...
 

Static Public Attributes

static const int INVAILD_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 int _maxInstances
 
static ProfileHelper_defaultProfileHelper
 
static AudioEngineImpl_audioEngineImpl
 

Friends

class AudioEngineImpl
 

Detailed Description

Note

Member Enumeration Documentation

enum 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
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
static AudioProfile* 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
static int 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
static AudioProfile* getProfile ( const std::string &  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
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)
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.
static bool lazyInit ( )
static
static void pause ( int  audioID)
static

Pause an audio instance.

Parameters
audioIDan audioID returned by the play2d function
static void 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.
static void remove ( int  audioID)
staticprotected
static void resume ( int  audioID)
static

Resume an audio instance.

Parameters
audioIDan audioID returned by the play2d function
static void 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
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
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
static bool setMaxAudioInstance ( int  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)
static void stop ( int  audioID)
static

Stop an audio instance.

Parameters
audioIDan audioID returned by the play2d function
static void 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
static void 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

Member Data Documentation

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

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