Skip to content

Commit

Permalink
Update multiple busy dialog crash workaround anxdpanic#891
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Aug 26, 2024
1 parent a6fb88f commit 0a68041
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ def cleanup_threads(self, only_ended=True):
self.threads = active_threads

def onPlayBackStarted(self):
if not self._ui.busy_dialog_active():
self._ui.clear_property(BUSY_FLAG)

if self._ui.get_property(PLAY_WITH):
self._context.execute('Action(SwitchPlayer)')
self._context.execute('Action(Stop)')
Expand All @@ -363,9 +366,6 @@ def onAVStarted(self):
if self._ui.get_property(PLAY_WITH):
return

if not self._ui.busy_dialog_active():
self._ui.clear_property(BUSY_FLAG)

playback_data = self._ui.pop_property(PLAYER_DATA)
if not playback_data:
return
Expand Down
128 changes: 64 additions & 64 deletions resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,65 +64,76 @@ def run(self, provider, context, focused=None):
self.handle = context.get_handle()
ui = context.get_ui()

if ui.pop_property(BUSY_FLAG).lower() == 'true':
if ui.busy_dialog_active():
xbmcplugin.endOfDirectory(
self.handle,
succeeded=False,
updateListing=True,
)
for was_busy in (ui.pop_property(BUSY_FLAG),):
if was_busy:
if ui.busy_dialog_active():
ui.set_property(BUSY_FLAG)
else:
break

xbmcplugin.endOfDirectory(
self.handle,
succeeded=False,
)

playlist = context.get_playlist_player()
position, remaining = playlist.get_position()
items = playlist.get_items()
playlist.clear()
playlist_player = context.get_playlist_player()

items = playlist_player.get_items()
if not items and not playlist_player.is_playing():
context.log_warning('Multiple busy dialogs active - '
'playlist cleared to avoid Kodi crash')

if position and items:
path = items[position - 1]['file']
old_path = ui.pop_property(PLAYLIST_PATH)
old_position = ui.pop_property(PLAYLIST_POSITION)
if (old_position and position == int(old_position)
and old_path and path == old_path):
if remaining:
position += 1
else:
items = None

if items:
max_wait_time = 30
while ui.busy_dialog_active():
max_wait_time -= 1
if max_wait_time < 0:
context.log_error('Multiple busy dialogs active - '
'extended busy period')
break
context.sleep(1)

context.log_warning('Multiple busy dialogs active - '
'reloading playlist')

num_items = playlist.add_items(items)
if playlist.is_playing():
return False
if position:
max_wait_time = min(position, num_items)
else:
position = 1
max_wait_time = num_items
while ui.busy_dialog_active() or playlist.size() < position:
max_wait_time -= 1
if max_wait_time < 0:
context.log_error('Multiple busy dialogs active - '
'unable to restart playback')
break
context.sleep(1)
'plugin call stopped to avoid Kodi crash')
break

playlist_player.clear()
context.log_warning('Multiple busy dialogs active - '
'playlist cleared to avoid Kodi crash')

position, remaining = playlist_player.get_position()
if position:
path = items[position - 1]['file']
old_path = ui.pop_property(PLAYLIST_PATH)
old_position = ui.pop_property(PLAYLIST_POSITION)
if (old_position and position == int(old_position)
and old_path and path == old_path):
if remaining:
position += 1
else:
playlist.play_playlist_item(position)
return False

max_wait_time = 30
while ui.busy_dialog_active():
max_wait_time -= 1
if max_wait_time < 0:
context.log_error('Multiple busy dialogs active - '
'extended busy period')
break
context.sleep(1)

context.log_warning('Multiple busy dialogs active - '
'reloading playlist')

num_items = playlist_player.add_items(items)
if playlist_player.is_playing():
return False

if position:
max_wait_time = min(position, num_items)
else:
position = 1
max_wait_time = num_items

while ui.busy_dialog_active() or playlist_player.size() < position:
max_wait_time -= 1
if max_wait_time < 0:
context.log_error('Multiple busy dialogs active - '
'unable to restart playback')
break
context.sleep(1)
else:
playlist_player.play_playlist_item(position)
else:
return False

if ui.get_property(PLUGIN_SLEEPING):
context.wakeup(PLUGIN_WAKEUP)

Expand Down Expand Up @@ -187,17 +198,6 @@ def run(self, provider, context, focused=None):
uri = result.get_uri()

if result.playable:
ui = context.get_ui()
if not context.is_plugin_path(uri) and ui.busy_dialog_active():
ui.set_property(BUSY_FLAG)
playlist = context.get_playlist_player()
position, _ = playlist.get_position()
items = playlist.get_items()
if position and items:
ui.set_property(PLAYLIST_PATH,
items[position - 1]['file'])
ui.set_property(PLAYLIST_POSITION, str(position))

item = self._PLAY_ITEM_MAP[result.__class__.__name__](
context,
result,
Expand Down
13 changes: 13 additions & 0 deletions resources/lib/youtube_plugin/youtube/helper/yt_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
from ..youtube_exceptions import YouTubeException
from ...kodion.compatibility import urlencode, urlunsplit
from ...kodion.constants import (
BUSY_FLAG,
PATHS,
PLAYBACK_INIT,
PLAYER_DATA,
PLAYLIST_PATH,
PLAYLIST_POSITION,
PLAY_FORCE_AUDIO,
PLAY_PROMPT_QUALITY,
PLAY_PROMPT_SUBTITLES,
Expand Down Expand Up @@ -340,6 +343,16 @@ def process(provider, context, **_kwargs):
if force_play:
context.execute('Action(Play)')
return False

ui.set_property(BUSY_FLAG)
playlist_player = context.get_playlist_player()
position, _ = playlist_player.get_position()
items = playlist_player.get_items()
if position and items:
ui.set_property(PLAYLIST_PATH,
items[position - 1]['file'])
ui.set_property(PLAYLIST_POSITION, str(position))

ui.clear_property(SERVER_POST_START)
context.wakeup(SERVER_WAKEUP, timeout=5)
media_item = _play_stream(provider, context)
Expand Down

0 comments on commit 0a68041

Please sign in to comment.