changeset 280:cad653e4f59c

pygame.mixer.Sound, I mildly dislikes you, I does
author Neil Muller <drnlmuller@gmail.com>
date Thu, 15 Sep 2011 19:58:24 +0200
parents 162bddbbc5d0
children 2008c49b5e95
files mamba/sound.py
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/sound.py	Thu Sep 15 18:21:09 2011 +0200
+++ b/mamba/sound.py	Thu Sep 15 19:58:24 2011 +0200
@@ -2,6 +2,7 @@
 
 from pygame import mixer
 import pygame
+import os.path
 
 from mamba import data
 from mamba.constants import FREQ, BITSIZE, CHANNELS, BUFFER
@@ -88,6 +89,12 @@
         if not self.sound_enabled:
             self._sounds[key] = None
         else:
+            if not os.path.exists(data.filepath(track_name)):
+                # Pygame doesn't error out for missing files, so
+                # handle that ourselves
+                print "Can't find sound %s. Skipping" % track_name
+                self._sounds[key] = None
+                return
             try:
                 self._sounds[key] = pygame.mixer.Sound(
                         data.filepath(track_name))