aboutsummaryrefslogtreecommitdiff
path: root/quiz.py
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-07-18 08:30:58 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-07-18 08:30:58 +0200
commit508deb2420652a5d6338d7d227d575935ef93371 (patch)
tree03bbaef4c2994b6f1c42084cc5db240f6d9552d5 /quiz.py
parent1f4725de6a902bed530663b71be3ec897e8c7b91 (diff)
downloadquiz-508deb2420652a5d6338d7d227d575935ef93371.tar.gz
quiz-508deb2420652a5d6338d7d227d575935ef93371.zip
use playsound instead of subprocess based own implementation
Diffstat (limited to 'quiz.py')
-rwxr-xr-xquiz.py19
1 files changed, 3 insertions, 16 deletions
diff --git a/quiz.py b/quiz.py
index a9248e3..f3b3c3e 100755
--- a/quiz.py
+++ b/quiz.py
@@ -24,15 +24,11 @@ import sys
import PySimpleGUI as sg
import psutil
+import playsound
WRONG_SOUND = Path(__file__).parent / 'Wrong.mp3'
CORRECT_SOUND = Path(__file__).parent / 'Correct.mp3'
-if platform.system() != 'Windows':
- PLAY_SOUND_CMD = 'mpv'
-else:
- PLAY_SOUND_CMD = 'vlc.exe --intf=dummy --dummy-quiet'
-
SHOW_QUESTION_CMD = 'xdg-open'
@@ -42,15 +38,6 @@ def err(msg: str, status=1):
sys.exit(status)
-def play_sound(sound: Path):
- """Play a sound file"""
- cmd = PLAY_SOUND_CMD.split() + [str(sound)]
- subprocess.run(cmd,
- check=True,
- stderr=subprocess.DEVNULL,
- stdout=subprocess.DEVNULL)
-
-
def terminate_subprocesses():
"""Terminate all started subprocesses"""
procs = psutil.Process().children(recursive=True)
@@ -186,10 +173,10 @@ def prompt_solution(solution: str, prompts=None):
break
color_button(layout[0], event, '#FF0000')
- play_sound(WRONG_SOUND)
+ playsound.playsound(WRONG_SOUND)
color_button(layout[0], event, '#00FF00')
- play_sound(CORRECT_SOUND)
+ playsound.playsound(CORRECT_SOUND)
window.read()
window.close()