AudioEngine-winrt.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * cocos2d-x http://www.cocos2d-x.org
  3. *
  4. * Copyright (c) 2010-2011 - cocos2d-x community
  5. *
  6. * Portions Copyright (c) Microsoft Open Technologies, Inc.
  7. * All Rights Reserved
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and limitations under the License.
  17. */
  18. #include "platform/CCPlatformConfig.h"
  19. #if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
  20. #ifndef __AUDIO_ENGINE_WINRT_H_
  21. #define __AUDIO_ENGINE_WINRT_H_
  22. #define NEAR near
  23. #include <unordered_map>
  24. #include "base/CCRef.h"
  25. #include "audio/include/AudioEngine.h"
  26. #include "audio/winrt/AudioCachePlayer.h"
  27. NS_CC_BEGIN
  28. namespace experimental{
  29. #define MAX_AUDIOINSTANCES 32
  30. class CC_DLL AudioEngineImpl : public cocos2d::Ref
  31. {
  32. public:
  33. AudioEngineImpl();
  34. ~AudioEngineImpl();
  35. bool init();
  36. int play2d(const std::string &fileFullPath, bool loop, float volume);
  37. void setVolume(int audioID, float volume);
  38. void setLoop(int audioID, bool loop);
  39. bool pause(int audioID);
  40. bool resume(int audioID);
  41. bool stop(int audioID);
  42. void stopAll();
  43. float getDuration(int audioID);
  44. float getCurrentTime(int audioID);
  45. bool setCurrentTime(int audioID, float time);
  46. void setFinishCallback(int audioID, const std::function<void(int, const std::string &)> &callback);
  47. void uncache(const std::string& filePath);
  48. void uncacheAll();
  49. AudioCache* preload(const std::string& filePath, std::function<void(bool)> callback);
  50. void update(float dt);
  51. private:
  52. void _play2d(AudioCache *cache, int audioID);
  53. private:
  54. std::unordered_map<int, AudioPlayer> _audioPlayers;
  55. std::unordered_map<std::string, AudioCache> _audioCaches;
  56. std::vector<AudioCache*> _toRemoveCaches;
  57. std::mutex _threadMutex;
  58. std::vector<int> _toRemoveAudioIDs;
  59. bool _lazyInitLoop;
  60. int _currentAudioID;
  61. };
  62. }
  63. NS_CC_END
  64. #endif // __AUDIO_ENGINE_WINRT_H_
  65. #endif