Skip to content

Commit

Permalink
Fix handling unresponsive cast devices
Browse files Browse the repository at this point in the history
  • Loading branch information
elibroftw committed Apr 22, 2024
1 parent 7ec8e91 commit 65318d5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions build_files/mc_version_info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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])])
]
Expand Down
2 changes: 1 addition & 1 deletion build_files/setup_script.iss
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/meta.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 25 additions & 9 deletions src/music_caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 65318d5

Please sign in to comment.