audio.py 704B

12345678910111213141516171819202122232425
  1. # coding: utf-8
  2. import typing
  3. from cocos.audio.pygame.mixer import Sound
  4. from synergine2_cocos2d.util import PathManager
  5. class AudioLibrary(object):
  6. # name: file_name
  7. sound_file_paths = {} # type: typing.Dict[str, str]
  8. def __init__(
  9. self,
  10. include_paths: typing.List[str],
  11. ) -> None:
  12. self._path_manager = PathManager(include_paths)
  13. self._sounds = {}
  14. def get_sound(self, name: str) -> Sound:
  15. if name not in self._sounds:
  16. sound_file_name = self.sound_file_paths[name]
  17. sound_file_path = self._path_manager.path(sound_file_name)
  18. self._sounds[name] = Sound(sound_file_path)
  19. return self._sounds[name]