[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] pygame.mixer.Sound doesn't throw file not found
- To: pygame-users@xxxxxxxx
- Subject: [pygame] pygame.mixer.Sound doesn't throw file not found
- From: Mark Reed <markreed99@xxxxxxxxx>
- Date: Fri, 25 Dec 2009 04:41:04 +0800
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Thu, 24 Dec 2009 15:41:07 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=RG1BU2q/I0oxYJjewxp1mruWbiLSA1Amov+diYmqpGw=; b=HriEE+HZjg87GNFjC8OSb+R19dtNLcySd6/4jZ9V26rjXlG9SjyOdbJD3nAs2bVV0L gc4thwoX6NAUruJPo3RmzsNc1MHPH/ZH3L7SNEyPyJG/pQXdMArHHAsFDKperypDK5xo GCvp653hCFGBAINYWPcQLv0mMD+7cp8HQ6z1c=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=kumCmkO896z3kEJzcAr9JxIIQS0yzpRcQj82hDN8/YrBx5Y1H8miDAdFeXJWvkGoht exVQ3fvxT0EI3Ud+zffX/0KtFZBMjr2nZmbN/WjFe8daozYHSGwKyUed8EmNoR1hhIWt XDFbv2Bz+vro3O+6CdD/+g/XweRHnz9ia7inE=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Been using pygame for 5 years and just noticed that pygame.mixer.Sound
doesn't throw anything on file not found. I'm guessing either it
should or we should update the example .py's to test for it. It took
quite awhile to debug this since you assume it would throw if it
couldn't load the sound from the file.
Heres chimp.py's load_sound which I copied a long time ago and use in
all my games. If the wav file is not there this function returns some
kind of silent sound object with no error.
def load_sound(name):
class NoneSound:
def play(self): pass
if not pygame.mixer or not pygame.mixer.get_init():
return NoneSound()
fullname = os.path.join(data_dir, name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error:
print ('Cannot load sound: %s' % fullname)
raise SystemExit(str(geterror()))
return sound