diff --git a/nava/functions.py b/nava/functions.py index 271328f..ab98c52 100644 --- a/nava/functions.py +++ b/nava/functions.py @@ -12,6 +12,7 @@ from .errors import NavaBaseError from . import params + def stop(sound_id): """ Stop sound. @@ -22,6 +23,7 @@ def stop(sound_id): """ params._play_threads_map[sound_id].stop() + def stop_all(): """ Stop all sounds. @@ -31,16 +33,18 @@ def stop_all(): for thread in params._play_threads_map.values(): thread.stop() + def sound_id_gen(): """ Sound id generator. :return: sound id as int """ - params._play_threads_counter +=1 + params._play_threads_counter += 1 sound_id = params._play_threads_counter + 1000 return sound_id + def nava_help(): """ Print nava details. @@ -75,6 +79,7 @@ def quoter(sound_path, *args, **kwargs): return func(sound_path, *args, **kwargs) return quoter + def __play_win(sound_path, async_mode=True): """ Play sound in Windows. @@ -125,8 +130,8 @@ def __play_linux(sound_path, async_mode=True): """ if async_mode: sound_thread = NavaThread(target=__play_sync_linux, - args=(sound_path,), - daemon=True) + args=(sound_path,), + daemon=True) sound_thread.start() sound_id = sound_id_gen() params._play_threads_map[sound_id] = sound_thread @@ -144,7 +149,7 @@ def __play_sync_linux(sound_path): :return: process """ proc = subprocess.Popen(["aplay", - sound_path], + sound_path], shell=False, stderr=subprocess.PIPE, stdin=subprocess.PIPE, @@ -152,7 +157,6 @@ def __play_sync_linux(sound_path): return proc - @quote def __play_mac(sound_path, async_mode=True): """ @@ -166,8 +170,8 @@ def __play_mac(sound_path, async_mode=True): """ if async_mode: sound_thread = NavaThread(target=__play_sync_mac, - args=(sound_path,), - daemon=True) + args=(sound_path,), + daemon=True) sound_thread.start() sound_id = sound_id_gen() params._play_threads_map[sound_id] = sound_thread @@ -185,11 +189,11 @@ def __play_sync_mac(sound_path): :return: process """ proc = subprocess.Popen(["afplay", - sound_path], - shell=False, - stderr=subprocess.PIPE, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE) + sound_path], + shell=False, + stderr=subprocess.PIPE, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) return proc @@ -240,5 +244,5 @@ def play(sound_path, async_mode=True): return __play_mac(sound_path, async_mode) else: return __play_linux(sound_path, async_mode) - except Exception: # pragma: no cover + except Exception: # pragma: no cover raise NavaBaseError(SOUND_FILE_PLAY_ERROR) diff --git a/nava/params.py b/nava/params.py index c6c26a7..2ca956f 100644 --- a/nava/params.py +++ b/nava/params.py @@ -13,4 +13,4 @@ SOUND_FILE_PATH_TYPE_ERROR = "Sound file's path should be a string." _play_threads_map = dict() -_play_threads_counter = 0 \ No newline at end of file +_play_threads_counter = 0 diff --git a/nava/thread.py b/nava/thread.py index 310c1ea..3395bbd 100644 --- a/nava/thread.py +++ b/nava/thread.py @@ -9,6 +9,7 @@ class NavaThread(threading.Thread): """ Nava custom thread. """ + def __init__(self, *args, **kwargs): """ Init method. @@ -43,4 +44,4 @@ def stop(self): else: if self.play_process is not None: self.play_process.kill() - self.play_process.terminate() \ No newline at end of file + self.play_process.terminate()