Skip to content

Commit

Permalink
fix : loop added to NavaThread
Browse files Browse the repository at this point in the history
  • Loading branch information
sepandhaghighi committed Mar 25, 2024
1 parent 2197474 commit cc50fc4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 5 additions & 3 deletions nava/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __play_win(sound_path, async_mode=False, loop=False):

if async_mode:
sound_thread = NavaThread(target=__play_win_flags,
args=(sound_path, play_flags), daemon=True)
args=(sound_path, play_flags), daemon=True, loop=loop)
sound_thread.start()
sound_id = sound_id_gen()
params._play_threads_map[sound_id] = sound_thread
Expand Down Expand Up @@ -141,7 +141,8 @@ def __play_linux(sound_path, async_mode=False, loop=False):
if async_mode:
sound_thread = NavaThread(target=__play_proc_linux,
args=(sound_path,),
daemon=True)
daemon=True,
loop=loop)
sound_thread.start()
sound_id = sound_id_gen()
params._play_threads_map[sound_id] = sound_thread
Expand Down Expand Up @@ -187,7 +188,8 @@ def __play_mac(sound_path, async_mode=False, loop=False):
if async_mode:
sound_thread = NavaThread(target=__play_proc_mac,
args=(sound_path,),
daemon=True)
daemon=True,
loop=loop)
sound_thread.start()
sound_id = sound_id_gen()
params._play_threads_map[sound_id] = sound_thread
Expand Down
15 changes: 12 additions & 3 deletions nava/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def __init__(self, *args, **kwargs):
:type kwargs: dict
"""
super(NavaThread, self).__init__(*args, **kwargs)
self.sys_platform = sys.platform
self.play_process = None
self.loop = kwargs["loop"]

def run(self):
"""
Expand All @@ -27,16 +29,23 @@ def run(self):
:return: None
"""
if self._target is not None:
self.play_process = self._target(*self._args, **self._kwargs)
if self.sys_platform != "win32":
self.play_process = self._target(*self._args, **self._kwargs)
else:
while True:
self.play_process = self._target(*self._args, **self._kwargs)
self.play_process.wait()
if not self.loop:
break


def stop(self):
"""
Stop sound.
:return: None
"""
sys_platform = sys.platform
if sys_platform == "win32":
if self.sys_platform == "win32":
import winsound
winsound.PlaySound(None, winsound.SND_PURGE)
else:
Expand Down

0 comments on commit cc50fc4

Please sign in to comment.