Skip to content

Commit

Permalink
Further fixes for multiple busy dialog crash workaround
Browse files Browse the repository at this point in the history
# Possibly fix issues reported in comments of anxdpanic#704
  • Loading branch information
MoojMidge committed Apr 17, 2024
1 parent f785997 commit 762a2d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
2 changes: 2 additions & 0 deletions resources/lib/youtube_plugin/kodion/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

BUSY_FLAG = 'busy'
SWITCH_PLAYER_FLAG = 'switch_player'
PLAYLIST_POSITION = 'playlist_position'
WAIT_FLAG = 'builtin_running'

__all__ = (
Expand All @@ -42,6 +43,7 @@
'BUSY_FLAG',
'DATA_PATH',
'MEDIA_PATH',
'PLAYLIST_POSITION',
'RESOURCE_PATH',
'SWITCH_PLAYER_FLAG',
'TEMP_PATH',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ def play_playlist_item(self, position, resume=False):
context.log_debug('Playing from playlist position: {0}'
.format(position))

if not resume:
xbmc.Player().play(self._playlist, startpos=position - 1)
return
# JSON Player.Open can be too slow but is needed if resuming is enabled
jsonrpc(method='Player.Open',
params={'item': {'playlistid': self._playlist.getPlayListId(),
# Convert 1 indexed to 0 indexed position
'position': position - 1}},
options={'resume': resume},
options={'resume': True},
no_response=True)

def get_position(self, offset=0):
Expand Down
38 changes: 19 additions & 19 deletions resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from traceback import format_stack

from ..abstract_plugin import AbstractPlugin
from ...constants import BUSY_FLAG
from ...constants import BUSY_FLAG, PLAYLIST_POSITION
from ...compatibility import xbmcplugin
from ...exceptions import KodionException
from ...items import (
Expand Down Expand Up @@ -42,27 +42,22 @@ def run(self, provider, context):
ui = context.get_ui()

if ui.get_property(BUSY_FLAG).lower() == 'true':
ui.clear_property(BUSY_FLAG)
if ui.busy_dialog_active():
playlist = XbmcPlaylist('auto', context, retry=3)
playlist.clear()
xbmcplugin.endOfDirectory(
self.handle,
succeeded=False,
updateListing=True,
)

playlist = XbmcPlaylist('auto', context, retry=3)
position, remaining = playlist.get_position()
items = playlist.get_items() if remaining else None
playlist.clear()

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

num_items = 0
items = ui.get_property('playlist')
position = ui.get_property('position')

if position and items:
position = int(position)
ui.clear_property('playlist')

if items:
max_wait_time = 30
while ui.busy_dialog_active():
max_wait_time -= 1
Expand All @@ -74,10 +69,12 @@ def run(self, provider, context):

context.log_warning('Multiple busy dialogs active - '
'reloading playlist')
num_items = playlist.add_items(items, loads=True)
num_items = playlist.add_items(items)

old_position = ui.get_property(PLAYLIST_POSITION)
if old_position and position == int(old_position):
position += 1

if position and num_items:
position += 1
max_wait_time = min(position, num_items)
while ui.busy_dialog_active() or playlist.size() < position:
max_wait_time -= 1
Expand All @@ -89,8 +86,13 @@ def run(self, provider, context):
else:
playlist.play_playlist_item(position)

ui.clear_property(BUSY_FLAG)
ui.clear_property(PLAYLIST_POSITION)
return False

ui.clear_property(BUSY_FLAG)
ui.clear_property(PLAYLIST_POSITION)

if settings.is_setup_wizard_enabled():
provider.run_wizard(context)

Expand Down Expand Up @@ -169,10 +171,8 @@ def _set_resolved_url(self, context, base_item, show_fanart):
if not context.is_plugin_path(uri) and ui.busy_dialog_active():
ui.set_property(BUSY_FLAG, 'true')
playlist = XbmcPlaylist('auto', context)
position, remaining = playlist.get_position()
if remaining:
ui.set_property('playlist', playlist.get_items(dumps=True))
ui.set_property('position', str(position))
position, _ = playlist.get_position()
ui.set_property(PLAYLIST_POSITION, str(position))

item = playback_item(context, base_item, show_fanart)
xbmcplugin.setResolvedUrl(self.handle,
Expand Down

0 comments on commit 762a2d3

Please sign in to comment.