Check if soundfiles exist for jeopardy music

This commit is contained in:
Sebastian Lohff 2013-12-02 22:54:51 +01:00
parent 649a714bb3
commit be4fd828c0
2 changed files with 7 additions and 1 deletions

View File

@ -1,5 +1,6 @@
from __future__ import print_function
import os
import sys
from PySide import phonon
@ -19,7 +20,10 @@ class MusicBox(object):
@classmethod
def add_music(clazz, name, media_path):
if name not in clazz.media.iterkeys():
if not os.path.isfile(media_path):
return False
clazz.media[name] = phonon.Phonon.MediaSource(media_path)
return True
@classmethod
def play_music(clazz, name):

View File

@ -59,7 +59,9 @@ if __name__ == '__main__':
MusicBox.init()
for name, path in config["music"].iteritems():
if path:
MusicBox.add_music(name, path)
if not MusicBox.add_music(name, path):
print("Error: Could not load music %s (file %s)" % (name, path), file=sys.stderr)
sys.exit(1)
# create board
board = SeopardyGame(questions, gamestate)