Browse Source

Check if soundfiles exist for jeopardy music

Sebastian Lohff 6 years ago
parent
commit
be4fd828c0
2 changed files with 7 additions and 1 deletions
  1. 4
    0
      music.py
  2. 3
    1
      seopardy.py

+ 4
- 0
music.py View File

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

+ 3
- 1
seopardy.py View File

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

Loading…
Cancel
Save