From 508deb2420652a5d6338d7d227d575935ef93371 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 18 Jul 2023 08:30:58 +0200 Subject: use playsound instead of subprocess based own implementation --- quiz.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'quiz.py') 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() -- cgit v1.2.3