ya2 · news · projects · code · about

configuration
[pmachines.git] / pmachines / music.py
CommitLineData
54a1397e
FC
1from glob import glob
2from random import choice
3from logging import info
4from panda3d.core import AudioSound
5
6
7class MusicMgr:
8
9ba5488b 9 def __init__(self, volume):
54a1397e 10 self._start_music(glob('assets/audio/music/*.ogg'))
9ba5488b
FC
11 base.musicManager.setVolume(.8 * volume)
12 base.sfxManagerList[0].setVolume(volume)
54a1397e
FC
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