diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-07-18 08:30:58 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-07-18 08:30:58 +0200 |
| commit | 508deb2420652a5d6338d7d227d575935ef93371 (patch) | |
| tree | 03bbaef4c2994b6f1c42084cc5db240f6d9552d5 /quiz.py | |
| parent | 1f4725de6a902bed530663b71be3ec897e8c7b91 (diff) | |
| download | quiz-508deb2420652a5d6338d7d227d575935ef93371.tar.gz quiz-508deb2420652a5d6338d7d227d575935ef93371.zip | |
use playsound instead of subprocess based own implementation
Diffstat (limited to 'quiz.py')
| -rwxr-xr-x | quiz.py | 19 |
1 files changed, 3 insertions, 16 deletions
@@ -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() |
