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 | |
| parent | 1f4725de6a902bed530663b71be3ec897e8c7b91 (diff) | |
| download | quiz-508deb2420652a5d6338d7d227d575935ef93371.tar.gz quiz-508deb2420652a5d6338d7d227d575935ef93371.zip | |
use playsound instead of subprocess based own implementation
| -rw-r--r-- | Pipfile | 1 | ||||
| -rw-r--r-- | Pipfile.lock | 9 | ||||
| -rwxr-xr-x | quiz.py | 19 |
3 files changed, 12 insertions, 17 deletions
@@ -6,6 +6,7 @@ name = "pypi" [packages] pysimplegui = "*" psutil = "*" +playsound = "*" [dev-packages] yapf = "*" diff --git a/Pipfile.lock b/Pipfile.lock index fea8966..bfdc635 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "6eee3e0bc56cbe8b817160150d65f011413ee574ec91664d2c5b52a1668d7016" + "sha256": "650e3ae04b710f3e337e2ee034cf586ba8d53629bcb446983191592de5ef1fc6" }, "pipfile-spec": 6, "requires": { @@ -16,6 +16,13 @@ ] }, "default": { + "playsound": { + "hashes": [ + "sha256:cc6ed11d773034b0ef624e6bb4bf50f4b76b8414a59ce6d38afb89b423297ced" + ], + "index": "pypi", + "version": "==1.3.0" + }, "psutil": { "hashes": [ "sha256:104a5cc0e31baa2bcf67900be36acde157756b9c44017b86b2c049f11957887d", @@ -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() |
