2014-01-07 11:47:11 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2017-02-14 14:36:57 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2014-01-07 11:47:11 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2017-09-20 09:05:00 +08:00
|
|
|
#ifndef __CDDANDROIDANDROIDJAVAENGINE_H__
|
|
|
|
#define __CDDANDROIDANDROIDJAVAENGINE_H__
|
2013-07-23 07:12:18 +08:00
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "audio/include/SimpleAudioEngine.h"
|
2013-07-18 05:49:07 +08:00
|
|
|
#include "platform/android/jni/JniHelper.h"
|
2015-06-26 10:16:52 +08:00
|
|
|
#include <list>
|
2013-07-23 07:12:18 +08:00
|
|
|
|
|
|
|
namespace CocosDenshion {
|
|
|
|
namespace android {
|
|
|
|
class AndroidJavaEngine : public SimpleAudioEngine {
|
2015-05-29 14:52:25 +08:00
|
|
|
public:
|
|
|
|
AndroidJavaEngine();
|
2013-07-23 07:12:18 +08:00
|
|
|
~AndroidJavaEngine();
|
|
|
|
|
2017-11-27 17:09:17 +08:00
|
|
|
/*
|
|
|
|
* @brief Preload background music.
|
|
|
|
* @param filePath The path of the background music file.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void preloadBackgroundMusic(const char* filePath);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Play background music.
|
|
|
|
* @param filePath The path of the background music file,or the FileName of T_SoundResInfo.
|
|
|
|
* @param loop Whether the background music loop or not.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void playBackgroundMusic(const char* filePath, bool loop);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Stop playing background music.
|
|
|
|
* @param releaseData If release the background music data or not.As default value is false.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void stopBackgroundMusic(bool releaseData);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Pause playing background music.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void pauseBackgroundMusic();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Resume playing background music.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void resumeBackgroundMusic();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Rewind playing background music
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void rewindBackgroundMusic();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Indicates whether any background music can be played or not.
|
|
|
|
* @return true if background music can be played; otherwise false.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual bool willPlayBackgroundMusic();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Indicates whether the background music is playing.
|
|
|
|
* @return true if the background music is playing; otherwise false.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual bool isBackgroundMusicPlaying();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Get the volume of the background music.
|
|
|
|
* @return the range of 0.0 as the minimum and 1.0 as the maximum.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual float getBackgroundMusicVolume();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Set the volume of the background music.
|
|
|
|
* @param volume must be range of 0.0 as the minimum and 1.0 as the maximum.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void setBackgroundMusicVolume(float volume);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Get the volume of the effects.
|
|
|
|
* @return the range of 0.0 as the minimum and 1.0 as the maximum.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual float getEffectsVolume();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Set the volume of sound effects.
|
|
|
|
* @param volume must be range of 0.0 as the minimum and 1.0 as the maximum.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void setEffectsVolume(float volume);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Play sound effect with a file path, pitch, pan, and gain.
|
|
|
|
* @param filePath The path of the effect file.
|
|
|
|
* @param loop Determines whether to loop the effect playing or not. The default value is false.
|
|
|
|
* @param pitch Fequency, normal value is 1.0. will also change effect play time.
|
|
|
|
* @param pan Stereo effect, in the range of [-1..1] where -1 enables only left channel.
|
|
|
|
* @param gain Volume, in the range of [0..1]. The normal value is 1.
|
|
|
|
* @return The sound id.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual unsigned int playEffect(const char* filePath, bool loop = false,
|
2013-07-25 07:58:37 +08:00
|
|
|
float pitch = 1.0f, float pan = 0.0f, float gain = 1.0f);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Pause playing sound effect.
|
|
|
|
* @param soundId The return value of function playEffect.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void pauseEffect(unsigned int soundId);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Pause all playing sound effect.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void pauseAllEffects();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Resume playing sound effect.
|
|
|
|
* @param soundId The return value of function playEffect.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void resumeEffect(unsigned int soundId);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Resume all playing sound effects.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void resumeAllEffects();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Stop playing sound effect.
|
|
|
|
* @param soundId The return value of function playEffect.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void stopEffect(unsigned int soundId);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Stop all playing sound effects.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void stopAllEffects();
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Preload a compressed audio file.
|
|
|
|
* @param filePath The path of the effect file.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void preloadEffect(const char* filePath);
|
2017-11-27 17:09:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Unload the preloaded effect from internal buffer.
|
|
|
|
* @param filePath The path of the effect file.
|
|
|
|
*/
|
2015-05-29 14:52:25 +08:00
|
|
|
virtual void unloadEffect(const char* filePath);
|
2013-07-18 05:49:07 +08:00
|
|
|
|
|
|
|
private :
|
2015-05-29 14:52:25 +08:00
|
|
|
bool _implementBaseOnAudioEngine;
|
|
|
|
float _effectVolume;
|
2015-06-26 10:16:52 +08:00
|
|
|
std::list<int> _soundIDs;
|
2013-07-23 07:12:18 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-20 09:05:00 +08:00
|
|
|
#endif //__CDDANDROIDANDROIDJAVAENGINE_H__
|