From 05cebe9527962ce5c179d07cb6193ab43381ef98 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 3 Feb 2022 16:46:41 +0500 Subject: [PATCH] Update playsound.py Fixed playback on Windows with block=false --- playsound.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/playsound.py b/playsound.py index 3692c91..41f1c5f 100644 --- a/playsound.py +++ b/playsound.py @@ -1,6 +1,8 @@ import logging logger = logging.getLogger(__name__) +_openedSoundsWin = [] + class PlaysoundException(Exception): pass @@ -52,12 +54,20 @@ def winCommand(*command): try: logger.debug('Starting') + if (sound in _openedSoundsWin): + winCommand(u'close {}'.format(sound)) + _openedSoundsWin.remove(sound) winCommand(u'open {}'.format(sound)) winCommand(u'play {}{}'.format(sound, ' wait' if block else '')) + if not block: + _openedSoundsWin.append(sound) logger.debug('Returning') finally: try: - winCommand(u'close {}'.format(sound)) + if (block): + winCommand(u'close {}'.format(sound)) + else: + pass except PlaysoundException: logger.warning(u'Failed to close the file: {}'.format(sound)) # If it fails, there's nothing more that can be done...