From 45fc9fa8bed8ceb9750bb031e06c0ac58f26592f Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 4 May 2019 16:13:26 +0200 Subject: [PATCH] Better way to detect video widget playback --- resources/lib/app/playstate.py | 3 --- resources/lib/kodimonitor.py | 11 ++--------- resources/lib/webservice.py | 15 ++------------- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/resources/lib/app/playstate.py b/resources/lib/app/playstate.py index 67430e87..7736ed17 100644 --- a/resources/lib/app/playstate.py +++ b/resources/lib/app/playstate.py @@ -59,9 +59,6 @@ class PlayState(object): self.resume_playback = None # Don't ask user whether to resume but immediatly resume self.autoplay = False - # Are we using the Kodi audio playlist (=True, e.g. for videos when - # starting from a widget!) or video playlist (=False)? - self.audioplaylist = None # Was the playback initiated by the user using the Kodi context menu? self.context_menu_play = False # Which Kodi player is/has been active? (either int 1, 2 or 3) diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index fd2c5591..44fbff92 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -184,7 +184,7 @@ class KodiMonitor(xbmc.Monitor): def _playlist_onadd(self, data): ''' - Detect widget playback. Widget for some reason, use audio playlists. + Called when a new item is added to a Kodi playqueue ''' if 'item' in data and data['item'].get('type') == v.KODI_TYPE_SHOW: # Hitting the "browse" button on tv show info dialog @@ -195,16 +195,9 @@ class KodiMonitor(xbmc.Monitor): return if data['position'] == 0: - if data['playlistid'] == 0: - app.PLAYSTATE.audioplaylist = True - LOG.error('app.PLAYSTATE.audioplaylist set to True') - else: - app.PLAYSTATE.audioplaylist = False - LOG.error('app.PLAYSTATE.audioplaylist set to False') self.playlistid = data['playlistid'] - LOG.debug('plex.playlist.start: %s', utils.window('plex.playlist.start')) if utils.window('plex.playlist.start') and data['position'] == int(utils.window('plex.playlist.start')): - LOG.info('Playlist ready') + LOG.debug('Playlist ready') utils.window('plex.playlist.ready', value='true') utils.window('plex.playlist.start', clear=True) diff --git a/resources/lib/webservice.py b/resources/lib/webservice.py index f5266f55..064d37c8 100644 --- a/resources/lib/webservice.py +++ b/resources/lib/webservice.py @@ -328,17 +328,8 @@ class QueuePlay(backgroundthread.KillableThread): LOG.debug('##===---- Starting QueuePlay ----===##') abort = False play_folder = False - i = 0 - while app.PLAYSTATE.audioplaylist is None: - # Needed particulary for widget-playback - # We need to wait until kodimonitor notification OnAdd is triggered - # in order to detect the playlist type (video vs. audio) and thus - # e.g. determine whether playback has been init. from widgets - xbmc.sleep(50) - i += 1 - if i > 100: - raise Exception('Kodi OnAdd not received - cancelling') - if app.PLAYSTATE.audioplaylist and self.plex_type in v.PLEX_VIDEOTYPES: + if (self.plex_type in v.PLEX_VIDEOTYPES and + xbmc.getCondVisibility('Window.IsVisible(Home.xml)')): # Video launched from a widget - which starts a Kodi AUDIO playlist # We will empty everything and start with a fresh VIDEO playlist LOG.debug('Widget video playback detected; relaunching') @@ -393,7 +384,6 @@ class QueuePlay(backgroundthread.KillableThread): elif video_widget_playback: LOG.info('Start widget video playback') utils.window('plex.playlist.play', value='true') - xbmc.sleep(2000) LOG.info('Current PKC queue: %s', playqueue) LOG.info('current Kodi queue: %s', js.playlist_get_items(playqueue.playlistid)) playqueue.start_playback() @@ -453,7 +443,6 @@ class QueuePlay(backgroundthread.KillableThread): utils.window('plex.playlist.ready', clear=True) utils.window('plex.playlist.start', clear=True) - app.PLAYSTATE.audioplaylist = None self.server.threads.remove(self) self.server.pending = [] LOG.debug('##===---- QueuePlay Stopped ----===##')