From 38669acc445dc4376968bf1bb885b8b205688a6e Mon Sep 17 00:00:00 2001 From: daniel-123 Date: Mon, 7 Jan 2013 21:26:48 +0100 Subject: [PATCH] Fix for exception due to missing buzzer.wav --- syncplay/ui/sound.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/syncplay/ui/sound.py b/syncplay/ui/sound.py index 1d00e6f..1cdc3cd 100644 --- a/syncplay/ui/sound.py +++ b/syncplay/ui/sound.py @@ -15,21 +15,24 @@ def doBuzz(): winsound.PlaySound(buzzPath, winsound.SND_FILENAME|winsound.SND_ASYNC) elif(alsaaudio): buzzPath = utils.findWorkingDir() + "/resources/buzzer.wav" - buzz = wave.open(buzzPath, 'rb') - device = alsaaudio.PCM(0) - device.setchannels(buzz.getnchannels()) - device.setrate(buzz.getframerate()) - if buzz.getsampwidth() == 1: - device.setformat(alsaaudio.PCM_FORMAT_U8) - elif buzz.getsampwidth() == 2: - device.setformat(alsaaudio.PCM_FORMAT_S16_LE) - else: - raise ValueError('Unsupported buzzer format') - device.setperiodsize(640) - data = buzz.readframes(640) - while data: - device.write(data) + print buzzPath + try: + buzz = wave.open(buzzPath, 'rb') + device = alsaaudio.PCM(0) + device.setchannels(buzz.getnchannels()) + device.setrate(buzz.getframerate()) + if buzz.getsampwidth() == 1: + device.setformat(alsaaudio.PCM_FORMAT_U8) + elif buzz.getsampwidth() == 2: + device.setformat(alsaaudio.PCM_FORMAT_S16_LE) + else: + raise ValueError('Unsupported buzzer format') + device.setperiodsize(640) data = buzz.readframes(640) - buzz.close() - + while data: + device.write(data) + data = buzz.readframes(640) + buzz.close() + except IOError: + pass