diff --git a/resources/lib/youtube_plugin/kodion/constants/__init__.py b/resources/lib/youtube_plugin/kodion/constants/__init__.py index 8ab679579..cdc7218d4 100644 --- a/resources/lib/youtube_plugin/kodion/constants/__init__.py +++ b/resources/lib/youtube_plugin/kodion/constants/__init__.py @@ -34,6 +34,7 @@ BUSY_FLAG = 'busy' SWITCH_PLAYER_FLAG = 'switch_player' +PLAYLIST_POSITION = 'playlist_position' WAIT_FLAG = 'builtin_running' __all__ = ( @@ -42,6 +43,7 @@ 'BUSY_FLAG', 'DATA_PATH', 'MEDIA_PATH', + 'PLAYLIST_POSITION', 'RESOURCE_PATH', 'SWITCH_PLAYER_FLAG', 'TEMP_PATH', diff --git a/resources/lib/youtube_plugin/kodion/player/xbmc/xbmc_playlist.py b/resources/lib/youtube_plugin/kodion/player/xbmc/xbmc_playlist.py index 9b66c6ae2..f35d7369e 100644 --- a/resources/lib/youtube_plugin/kodion/player/xbmc/xbmc_playlist.py +++ b/resources/lib/youtube_plugin/kodion/player/xbmc/xbmc_playlist.py @@ -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): diff --git a/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py b/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py index b70cd2d0a..16c3feb6c 100644 --- a/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py +++ b/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py @@ -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 ( @@ -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 @@ -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 @@ -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) @@ -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,