From 65318d543655775a2db437f0b7c2d61eefad83b0 Mon Sep 17 00:00:00 2001 From: Elijah Lopez Date: Sun, 21 Apr 2024 23:27:01 -0400 Subject: [PATCH] Fix handling unresponsive cast devices --- CHANGELOG.txt | 5 ++++- build_files/mc_version_info.txt | 8 ++++---- build_files/setup_script.iss | 2 +- src/meta.py | 2 +- src/music_caster.py | 34 ++++++++++++++++++++++++--------- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d595f2b3..94cc58aa 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,7 +1,10 @@ Music Caster by Elijah Lopez Changelog +5.19.5 +- [Fix] Handling unresponsive cast device + 5.19.4 -- [Fix] Fix crash when playing +- [Fix] Crash when playing 5.19.3 - [Fix] Cast syncing diff --git a/build_files/mc_version_info.txt b/build_files/mc_version_info.txt index 20c0b289..b0d4fce4 100644 --- a/build_files/mc_version_info.txt +++ b/build_files/mc_version_info.txt @@ -2,8 +2,8 @@ # For more details about fixed file info 'ffi' see: http://msdn.microsoft.com/en-us/library/ms646997.aspx VSVersionInfo( ffi=FixedFileInfo( - prodvers=(5, 19, 4, 0), - filevers=(5, 19, 4, 0), + prodvers=(5, 19, 5, 0), + filevers=(5, 19, 5, 0), # Contains a bitmask that specifies the valid bits 'flags'r mask=0x17, # Contains a bitmask that specifies the Boolean attributes of the file. @@ -27,12 +27,12 @@ VSVersionInfo( '000004b0', [StringStruct('CompanyName', 'Elijah Lopez'), StringStruct('FileDescription', 'Music Caster'), - StringStruct('FileVersion', '5.19.4.0'), + StringStruct('FileVersion', '5.19.5.0'), StringStruct('InternalName', 'Music Caster'), StringStruct('LegalCopyright', 'Copyright (c) 2019 - 2024, Elijah Lopez'), StringStruct('OriginalFilename', 'Music Caster.exe'), StringStruct('ProductName', 'Music Caster'), - StringStruct('ProductVersion', '5.19.4.0')]) + StringStruct('ProductVersion', '5.19.5.0')]) ]), VarFileInfo([VarStruct('Translation', [0, 1200])]) ] diff --git a/build_files/setup_script.iss b/build_files/setup_script.iss index 48375a24..47a8043a 100644 --- a/build_files/setup_script.iss +++ b/build_files/setup_script.iss @@ -1,5 +1,5 @@ #define MyAppName "Music Caster" -#define MyAppVersion "5.19.4" +#define MyAppVersion "5.19.5" #define MyAppPublisher "Elijah Lopez" #define MyAppURL "https://elijahlopez.ca/software#music-caster" #define MyAppExeName "Music Caster.exe" diff --git a/src/meta.py b/src/meta.py index fb6d87bc..5c1db252 100644 --- a/src/meta.py +++ b/src/meta.py @@ -1,4 +1,4 @@ -VERSION = latest_version = '5.19.4' +VERSION = latest_version = '5.19.5' UPDATE_MESSAGE = """ [NEW] Better Error Capturing [MSG] Language translators wanted diff --git a/src/music_caster.py b/src/music_caster.py index 0e574559..cab32c17 100644 --- a/src/music_caster.py +++ b/src/music_caster.py @@ -1130,8 +1130,16 @@ def api_system_audio(get_thumb=''): return Response(sar.get_audio_data(settings['sys_audio_delay'])) - def cast_try_reconnect(): + def cast_try_reconnect(switch_twice=False): global cast_browser, zconf + if switch_twice and cast is not None: + app_log.info('try changing devices to local and then back to cast') + cast_uuid = cast.uuid + if not playing_status.playing(): + change_device() + change_device(cast_uuid) + app_log.info('try changing devices to local and then back to cast') + app_log.info('stop discovery') cast_browser.stop_discovery() zconf = zeroconf.Zeroconf() cast_browser = pychromecast.discovery.CastBrowser(MyCastListener(), zconf) @@ -1250,7 +1258,7 @@ def change_device(new_uuid='local'): new_device = None except UnboundLocalError as e: app_log.error('Could not connect to cast device', exc_info=e) - tray_notify(t('ERROR') + ': ' + t('Could not connect to cast device') + ' (cd)') + tray_notify(t('ERROR') + ': ' + t('Could not connect to cast device')) return False if cast == new_device: # do not change device if local device is selected again @@ -1276,13 +1284,19 @@ def change_device(new_uuid='local'): update_settings('device', None if cast is None else str(cast.uuid)) refresh_tray(True) if was_busy and (music_queue or sar.alive): - if not sar.alive: - play(position=current_pos, autoplay=autoplay, switching_device=True) - else: + app_log.info('continuing playback on new device') + if sar.alive: play_system_audio(switching_device=True) + else: + play(position=current_pos, autoplay=autoplay, switching_device=True, show_error=True) else: if cast is not None: - cast.wait(timeout=WAIT_TIMEOUT) + with suppress(NotConnected): + cast.quit_app() + try: + cast.wait(timeout=WAIT_TIMEOUT) + except RequestTimeout: + tray_notify(t('ERROR') + ': ' + t('Could not connect to cast device')) update_volume(0 if settings['muted'] else settings['volume'], 'change_device') return True @@ -1946,15 +1960,16 @@ def play(position=0, autoplay=True, switching_device=False, show_error=False, fr tray_notify(t('ERROR') + ': ' + t('Could not connect to cast device') + ' (play)') change_device() return False - cast_try_reconnect() return play(position=position, autoplay=autoplay, switching_device=switching_device, show_error=True) except (PyChromecastError, OSError, RuntimeError, AssertionError) as e: app_log.error(f'play failed to cast {repr(e)}') if show_error: tray_notify(t('ERROR') + ': ' + t('Could not connect to cast device') + ' (play)') change_device() - return handle_exception(e) - cast_try_reconnect() + handle_exception(e) + switching_device=True + else: + cast_try_reconnect() return play(position=position, autoplay=autoplay, switching_device=switching_device, show_error=True) track_position = position track_start = time.monotonic() - track_position @@ -2287,6 +2302,7 @@ def set_pos(new_position): sets position of audio player or cast to new_position """ global track_position, track_start, track_end, SYNC_WITH_CHROMECAST + app_log.info('acquiring CAST_LOCK') with CAST_LOCK: t1 = time.time() app_log.info('trying to set playback position')