From 4a56885e33f0e9585904e4fd0061f5ccfd838f56 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 3 Aug 2023 21:11:55 +0300 Subject: [PATCH] try catch f*ck the music volume --- src/android_termux_api.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/android_termux_api.py b/src/android_termux_api.py index b5b38d7..a9fbbc8 100644 --- a/src/android_termux_api.py +++ b/src/android_termux_api.py @@ -12,12 +12,13 @@ from loguru import logger def handle_vol_lvl_as_switch_track(): volume_diff = [] while True: - debug_time = time.time() - volume = subprocess.Popen("termux-volume", stdout=subprocess.PIPE).stdout - json_volume = json.loads(volume.read()) - for i in json_volume: - if i['stream'] == 'music': - volume_diff.append(i['volume']) + for a in range(2): # ~2 secs + volume = subprocess.Popen("termux-volume", stdout=subprocess.PIPE).stdout + json_volume = json.loads(volume.read()) + time.sleep(0.300) + for i in json_volume: + if i['stream'] == 'music': + volume_diff.append(i['volume']) if len(volume_diff) == 2: before, after = volume_diff difference = after - before @@ -27,11 +28,13 @@ def handle_vol_lvl_as_switch_track(): except: pass os.system(f'termux-volume music {before}') + elif difference == -2: + try: + player.playlist_prev() + except: + pass + os.system(f'termux-volume music {before}') volume_diff = [] - debug_time2 = time.time() - total = debug_time2 - debug_time - print(total) - time.sleep(0.300) handle_vol_lvl = threading.Thread(