Skip to content

Commit 1d24e32

Browse files
committed
Fix death loop when cast is unresponsive when switching to local device
1 parent ed30615 commit 1d24e32

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Music Caster Changelog
22

3+
5.23.7
4+
- [Fix] Death loop
5+
36
5.23.6
47
- [Fix] URL processing
58

src/meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = latest_version = '5.23.6'
1+
VERSION = latest_version = '5.23.7'
22
UPDATE_MESSAGE = """
33
[NEW] Support "System Audio" in CLI
44
[MSG] Language translators wanted

src/music_caster.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ def get_device(device_uuid):
14311431
return pychromecast.get_chromecast_from_cast_info(cast_browser.devices[device_uuid], zconf)
14321432

14331433

1434-
def change_device(new_uuid='local'):
1434+
def change_device(new_uuid='local', unresponsive_cast=False):
14351435
"""switch_device
14361436
if new_uuid is invalid, then the local device is selected
14371437
"""
@@ -1464,15 +1464,15 @@ def change_device(new_uuid='local'):
14641464
# cache information
14651465
current_pos = 0
14661466
if cast is not None and cast.app_id == APP_MEDIA_RECEIVER:
1467-
if playing_status.busy():
1467+
if not unresponsive_cast and playing_status.busy():
14681468
mc = cast.media_controller
14691469
with suppress(PyChromecastError, AssertionError):
14701470
mc.update_status() # Switch device without playback loss
14711471
current_pos = mc.status.adjusted_current_time
14721472
if mc.status.player_is_playing or mc.status.player_is_paused:
14731473
mc.stop()
14741474
with suppress(PyChromecastError, AssertionError):
1475-
cast.quit_app(30)
1475+
cast.quit_app(10)
14761476
elif cast is None and 'audio_player' in globals() and audio_player.is_busy():
14771477
current_pos = audio_player.stop()
14781478
autoplay = playing_status.playing()
@@ -1763,7 +1763,7 @@ def play_system_audio(switching_device=False, show_error=False):
17631763
app_log.error(f'play_sys_audio failed to cast {repr(e)}')
17641764
if show_error:
17651765
tray_notify(t('ERROR') + ': ' + t('Could not connect to cast device') + ' (psa)')
1766-
change_device()
1766+
change_device(unresponsive_cast=True)
17671767
return handle_exception(e)
17681768
cast_try_reconnect()
17691769
return play_system_audio(switching_device=switching_device, show_error=True)
@@ -2098,7 +2098,7 @@ def play_url(position=0, autoplay=True, switching_device=False, show_error=False
20982098
+ t('Could not connect to cast device')
20992099
+ ' (play_url)'
21002100
)
2101-
change_device()
2101+
change_device(unresponsive_cast=True)
21022102
return False
21032103
except (PyChromecastError, OSError) as e:
21042104
app_log.error(f'play_url failed to cast {repr(e)}')
@@ -2201,7 +2201,7 @@ def play(position=0, autoplay=True, switching_device=False, show_error=False, fr
22012201
print(e)
22022202
if show_error:
22032203
tray_notify(t('ERROR') + ': ' + t('Could not connect to cast device') + ' (play)')
2204-
change_device()
2204+
change_device(unresponsive_cast=True)
22052205
return False
22062206
return play(position=position, autoplay=autoplay, switching_device=switching_device, show_error=True)
22072207
except (PyChromecastError, OSError, RuntimeError, AssertionError) as e:
@@ -2229,7 +2229,7 @@ def play(position=0, autoplay=True, switching_device=False, show_error=False, fr
22292229
show_error = True
22302230
if show_error:
22312231
tray_notify(t('ERROR') + ': ' + t('Could not connect to cast device') + ' (play)')
2232-
change_device()
2232+
change_device(unresponsive_cast=True)
22332233
handle_exception(e)
22342234
switching_device=True
22352235
return play(position=position, autoplay=autoplay, switching_device=switching_device, show_error=True)

0 commit comments

Comments
 (0)