Cocos2d-x  v3.10
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
AudioEngine Class Reference

Offers a interface to play audio. More...

Public Types

enum  AudioState
 AudioState enum,all possible states of an audio instance.
 

Static Public Member Functions

static void end ()
 Release objects relating to AudioEngine. More...
 
local end ()
 Release objects relating to AudioEngine. More...
 
static AudioProfile * 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.
 
static void resume (int audioID)
 Resume an audio instance. More...
 
local resume ( local audioID)
 Resume an audio instance. More...
 
static void resumeAll ()
 Resume all suspended audio instances.
 
local resumeAll ()
 Resume all suspended audio instances.
 
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.
 
static bool setCurrentTime (int audioID, float sec)
 Sets the current playback position of an audio instance. More...
 
local setCurrentTime ( local audioID, local sec)
 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...
 
local setFinishCallback ( local audioID, local int, local callback)
 Register a callback to be invoked when an audio instance has completed playing. More...
 
static int getMaxAudioInstance ()
 Gets the maximum number of simultaneous audio instance of AudioEngine.
 
static bool setMaxAudioInstance (int maxInstances)
 Sets the maximum number of simultaneous audio instance for AudioEngine. More...
 
local setMaxAudioInstance ( local maxInstances)
 Sets the maximum number of simultaneous audio instance for AudioEngine. More...
 
static void uncache (const std::string &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...
 
local uncacheAll ()
 Uncache all audio data from internal buffer. More...
 
static AudioProfile * getProfile (int audioID)
 Gets the audio profile by id of audio instance. More...
 
static AudioProfile * getProfile (const std::string &profileName)
 Gets an audio profile by name. More...
 
static void preload (const std::string &filePath)
 Preload audio file. More...
 
static void preload (const std::string &filePath, std::function< void(bool isSuccess)> callback)
 Preload audio file. More...
 
local preload ( local filePath, local callback)
 Preload audio file. More...
 

Detailed Description

Offers a interface to play audio.

Make sure to call AudioEngine::end() when the audio engine is not needed anymore to release resources.

Member Function Documentation

static void end ( )
static

Release objects relating to AudioEngine.

It must be called before the application exit.

local end ( )
static

Release objects relating to AudioEngine.

It must be called before the application exit.

static AudioProfile*
getDefaultProfile
( )
static

Gets the default profile of audio instances.

The default profile of audio instances.

local getDefaultProfile ( )
static

Gets the default profile of audio instances.

The default profile of audio instances.

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

Play 2d sound.

The path of an audio file. Whether audio instance loop or not. Volume value (range from 0.0 to 1.0). A profile for audio instance. When profile is not specified, default profile will be used. 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.

The path of an audio file. Whether audio instance loop or not. Volume value (range from 0.0 to 1.0). A profile for audio instance. When profile is not specified, default profile will be used. An audio ID. It allows you to dynamically change the behavior of an audio instance on the fly.

static void setLoop ( int  audioID,
bool  loop 
)
static

Sets whether an audio instance loop or not.

An audioID returned by the play2d function. Whether audio instance loop or not.

local setLoop ( local  audioID,
local  loop 
)
static

Sets whether an audio instance loop or not.

An audioID returned by the play2d function. Whether audio instance loop or not.

static bool isLoop ( int  audioID)
static

Checks whether an audio instance is loop.

An audioID returned by the play2d function. Whether or not an audio instance is loop.

local isLoop ( local  audioID)
static

Checks whether an audio instance is loop.

An audioID returned by the play2d function. Whether or not an audio instance is loop.

static void setVolume ( int  audioID,
float  volume 
)
static

Sets volume for an audio instance.

An audioID returned by the play2d function. Volume value (range from 0.0 to 1.0).

local setVolume ( local  audioID,
local  volume 
)
static

Sets volume for an audio instance.

An audioID returned by the play2d function. Volume value (range from 0.0 to 1.0).

static float getVolume ( int  audioID)
static

Gets the volume value of an audio instance.

An audioID returned by the play2d function. Volume value (range from 0.0 to 1.0).

local getVolume ( local  audioID)
static

Gets the volume value of an audio instance.

An audioID returned by the play2d function. Volume value (range from 0.0 to 1.0).

static void pause ( int  audioID)
static

Pause an audio instance.

An audioID returned by the play2d function.

local pause ( local  audioID)
static

Pause an audio instance.

An audioID returned by the play2d function.

static void resume ( int  audioID)
static

Resume an audio instance.

An audioID returned by the play2d function.

local resume ( local  audioID)
static

Resume an audio instance.

An audioID returned by the play2d function.

static void stop ( int  audioID)
static

Stop an audio instance.

An audioID returned by the play2d function.

local stop ( local  audioID)
static

Stop an audio instance.

An audioID returned by the play2d function.

static bool setCurrentTime ( int  audioID,
float  sec 
)
static

Sets the current playback position of an audio instance.

An audioID returned by the play2d function. The offset in seconds from the start to seek to.

local setCurrentTime ( local  audioID,
local  sec 
)
static

Sets the current playback position of an audio instance.

An audioID returned by the play2d function. The offset in seconds from the start to seek to.

static float getCurrentTime ( int  audioID)
static

Gets the current playback position of an audio instance.

An audioID returned by the play2d function. The current playback position of an audio instance.

local getCurrentTime ( local  audioID)
static

Gets the current playback position of an audio instance.

An audioID returned by the play2d function. The current playback position of an audio instance.

static float getDuration ( int  audioID)
static

Gets the duration of an audio instance.

An audioID returned by the play2d function. The duration of an audio instance.

local getDuration ( local  audioID)
static

Gets the duration of an audio instance.

An audioID returned by the play2d function. The duration of an audio instance.

static AudioState getState ( int  audioID)
static

Returns the state of an audio instance.

An audioID returned by the play2d function. The status of an audio instance.

local getState ( local  audioID)
static

Returns the state of an audio instance.

An audioID returned by the play2d function. The status of an audio instance.

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.

An 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.

An audioID returned by the play2d function. callback

static bool setMaxAudioInstance ( int  maxInstances)
static

Sets the maximum number of simultaneous audio instance for AudioEngine.

The maximum number of simultaneous audio instance.

local setMaxAudioInstance ( local  maxInstances)
static

Sets the maximum number of simultaneous audio instance for AudioEngine.

The maximum number of simultaneous audio instance.

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

Uncache the audio data from internal buffer.

AudioEngine cache audio data on ios,mac, and win32 platform.

This can lead to stop related audio first. Audio file path.

local uncache ( local  filePath)
static

Uncache the audio data from internal buffer.

AudioEngine cache audio data on ios,mac, and win32 platform.

This can lead to stop related audio first. Audio file path.

static void uncacheAll ( )
static

Uncache all audio data from internal buffer.

All audio will be stopped first.

local uncacheAll ( )
static

Uncache all audio data from internal buffer.

All audio will be stopped first.

static AudioProfile* getProfile ( int  audioID)
static

Gets the audio profile by id of audio instance.

An audioID returned by the play2d function. The audio profile.

local getProfile ( local  audioID)
static

Gets the audio profile by id of audio instance.

An audioID returned by the play2d function. The audio profile.

static AudioProfile* getProfile ( const std::string &  profileName)
static

Gets an audio profile by name.

A name of audio profile. The audio profile.

local getProfile ( local  profileName)
static

Gets an audio profile by name.

A name of audio profile. The audio profile.

static void preload ( const std::string &  filePath)
inlinestatic

Preload audio file.

Parameters
filePathThe file path of an audio.
local preload ( local  filePath)
inlinestatic

Preload audio file.

Parameters
filePathThe file path of an audio.
static void preload ( const std::string &  filePath,
std::function< void(bool isSuccess)>  callback 
)
static

Preload audio file.

Parameters
filePathThe file path of an audio.
callbackA callback which will be called after loading is finished.
local preload ( local  filePath,
local  callback 
)
static

Preload audio file.

Parameters
filePathThe file path of an audio.
callbackA callback which will be called after loading is finished.

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