comparison pyntnclick/sound.py @ 577:ccc26c23d2c1 pyntnclick

Fix sound loading
author Neil Muller <neil@dip.sun.ac.za>
date Sat, 11 Feb 2012 16:04:45 +0200
parents 1b1ab71535bd
children 66c2e084b8b3
comparison
equal deleted inserted replaced
576:1b1ab71535bd 577:ccc26c23d2c1
83 print 'Sound disabled' 83 print 'Sound disabled'
84 84
85 def get_sound(self, *names): 85 def get_sound(self, *names):
86 if not self.sound_enabled: 86 if not self.sound_enabled:
87 return DummySound() 87 return DummySound()
88 soundfile = os.path.join(names)
89 sound = None 88 sound = None
90 try: 89 try:
91 path = self._resource_finder("sounds", soundfile) 90 path = self._resource_finder.get_resource_path("sounds", *names)
92 sound = self.sound_cache.get(path, None) 91 sound = self.sound_cache.get(path, None)
93 except ResourceNotFound: 92 except ResourceNotFound:
94 print "Sound file not found: %s" % soundfile 93 print "Sound file not found: %s" % names
95 # Cache failed lookup 94 # Cache failed lookup
96 sound = DummySound() 95 sound = DummySound()
97 self.sound_cache[path] = sound 96 self.sound_cache[path] = sound
98 if sound is None: 97 if sound is None:
99 try: 98 try:
100 sound = pygame_Sound(path) 99 sound = pygame_Sound(path)
101 except pygame.error: 100 except pygame.error:
102 print "Sound file not found: %s" % soundfile 101 print "Sound file not found: %s" % names
103 sound = DummySound() 102 sound = DummySound()
104 self.sound_cache[path] = sound 103 self.sound_cache[path] = sound
105 return sound 104 return sound
106 105
107 def get_playlist(self, pieces, random=False, repeat=False): 106 def get_playlist(self, pieces, random=False, repeat=False):
108 return albow.music.PlayList(pieces, random, repeat) 107 return albow.music.PlayList(pieces, random, repeat)
109 108
110 def get_music(self, name, prefix): 109 def get_music(self, name, prefix):
111 return albow.music.get_music(name, prefix=prefix) 110 if self.sound_enabled:
111 return albow.music.get_music(name, prefix=prefix)
112 112
113 def change_playlist(self, new_playlist): 113 def change_playlist(self, new_playlist):
114 albow.music.change_playlist(new_playlist) 114 if self.sound_enabled:
115 albow.music.change_playlist(new_playlist)
115 116
116 def get_current_playlist(): 117 def get_current_playlist(self):
117 if albow.music.music_enabled and albow.music.current_playlist: 118 if self.sound_enabled and albow.music.music_enabled and \
119 albow.music.current_playlist:
118 return albow.music.current_playlist 120 return albow.music.current_playlist
119 121
120 122
121 def start_next_music(): 123 def start_next_music():
122 """Start playing the next item from the current playlist immediately.""" 124 """Start playing the next item from the current playlist immediately."""