2 from pygame import mixer
4 from .constants import (FREQ, BITSIZE, CHANNELS, BUFFER, DEFAULT_VOLUME,
6 from .loader import loader
9 class SoundManager(object):
12 """This is not in __init__, because we want to delay until after
13 other pygame initialistion"""
16 mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER)
17 silence = loader.load_sound("silence.ogg")
18 if silence.get_length() < 1:
19 raise RuntimeError("Sound load error - silence.ogg too short")
21 self.play_sound("silence.ogg")
23 except Exception, err:
24 print "Failed to enable sound: %r" % err
26 def play_sound(self, name, volume=DEFAULT_VOLUME):
28 sound = loader.load_sound(name)
30 sound.set_volume(volume)
33 def play_music(self, name, volume=DEFAULT_VOLUME):
42 sound = SoundManager()