CCComAudio.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /****************************************************************************
  2. Copyright (c) 2013-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CC_EXTENTIONS_CCCOMAUDIO_H__
  21. #define __CC_EXTENTIONS_CCCOMAUDIO_H__
  22. #include "editor-support/cocostudio/CCComBase.h"
  23. #include "base/CCProtocols.h"
  24. #include "2d/CCComponent.h"
  25. #include "editor-support/cocostudio/CocosStudioExport.h"
  26. namespace cocostudio {
  27. class CC_STUDIO_DLL ComAudio : public cocos2d::Component, public cocos2d::PlayableProtocol
  28. {
  29. DECLARE_CLASS_COMPONENT_INFO
  30. public:
  31. const static std::string COMPONENT_NAME;
  32. /**
  33. * @js ctor
  34. */
  35. ComAudio();
  36. /**
  37. * @js NA
  38. * @lua NA
  39. */
  40. virtual ~ComAudio();
  41. public:
  42. static ComAudio* create();
  43. virtual bool init() override;
  44. /**
  45. * @js NA
  46. * @lua NA
  47. */
  48. virtual void onEnter() override;
  49. /**
  50. * @js NA
  51. * @lua NA
  52. */
  53. virtual void onExit() override;
  54. /**
  55. * @js NA
  56. * @lua NA
  57. */
  58. virtual void onAdd() override;
  59. /**
  60. * @js NA
  61. * @lua NA
  62. */
  63. virtual void onRemove() override;
  64. virtual bool serialize(void* r) override;
  65. public:
  66. /**
  67. * @lua endToLua
  68. */
  69. void end();
  70. void preloadBackgroundMusic(const char* pszFilePath);
  71. void playBackgroundMusic(const char* pszFilePath, bool bLoop);
  72. void playBackgroundMusic(const char* pszFilePath);
  73. void playBackgroundMusic();
  74. void stopBackgroundMusic(bool bReleaseData);
  75. void stopBackgroundMusic();
  76. void pauseBackgroundMusic();
  77. void resumeBackgroundMusic();
  78. void rewindBackgroundMusic();
  79. bool willPlayBackgroundMusic();
  80. bool isBackgroundMusicPlaying();
  81. float getBackgroundMusicVolume();
  82. void setBackgroundMusicVolume(float volume);
  83. float getEffectsVolume();
  84. void setEffectsVolume(float volume);
  85. unsigned int playEffect(const char* pszFilePath, bool bLoop);
  86. unsigned int playEffect(const char* pszFilePath);
  87. unsigned int playEffect();
  88. void pauseEffect(unsigned int nSoundId);
  89. void pauseAllEffects();
  90. void resumeEffect(unsigned int nSoundId);
  91. void resumeAllEffects();
  92. void stopEffect(unsigned int nSoundId);
  93. void stopAllEffects();
  94. void preloadEffect(const char* pszFilePath);
  95. void unloadEffect(const char* pszFilePath);
  96. void setFile(const char* pszFilePath);
  97. const char* getFile();
  98. void setLoop(bool bLoop);
  99. bool isLoop();
  100. /// @{
  101. /// @name implement Playable Protocol
  102. // play the effect sound path in _filePath
  103. virtual void start() override;
  104. // stop the effect sound which started with latest start()
  105. virtual void stop() override;
  106. /// @} end of PlayableProtocol
  107. private:
  108. std::string _filePath;
  109. bool _loop;
  110. unsigned int _startedSoundId; // !playing sound id from start(), not playEffect
  111. };
  112. }
  113. #endif // __CC_EXTENTIONS_CCCOMAUDIO_H__