ya2 · news · projects · code · about

audio
[pmachines.git] / pmachines / music.py
1 from glob import glob
2 from random import choice
3 from logging import info
4 from panda3d.core import AudioSound
5
6
7 class MusicMgr:
8
9 def __init__(self):
10 self._start_music(glob('assets/audio/music/*.ogg'))
11 base.musicManager.setVolume(.8)
12 base.sfxManagerList[0].setVolume(1)
13 taskMgr.add(self._on_frame, 'on frame music')
14
15 def _start_music(self, files):
16 self._music = loader.load_music(choice(files))
17 info('playing music ' + self._music.get_name())
18 self._music.play()
19
20 def _on_frame(self, task):
21 if self._music.status() == AudioSound.READY:
22 files = glob('assets/audio/music/*.ogg')
23 files.remove('assets/audio/music/' + self._music.get_name())
24 self._start_music(files)
25 return task.cont