Fixes to add-on paths playback startup

This commit is contained in:
croneter 2018-03-06 18:23:56 +01:00
parent 5af5412009
commit 62e973dbe2
3 changed files with 27 additions and 13 deletions

View file

@ -209,17 +209,15 @@ class KodiMonitor(Monitor):
}
Will NOT be called if playback initiated by Kodi widgets
"""
kodi_item = js.get_item(data['playlistid'])
if (state.RESUMABLE is True and not kodi_item['file'] and
data['position'] == 0 and
data['item'].get('title') is not None and
getCondVisibility('Window.IsVisible(MyVideoNav.xml)')):
old = state.OLD_PLAYER_STATES[data['playlistid']]
if (not state.DIRECT_PATHS and data['position'] == 0 and
not PQ.PLAYQUEUES[data['playlistid']].items and
data['item']['type'] == old['kodi_type'] and
data['item']['id'] == old['kodi_id']):
# Hack we need for RESUMABLE items because Kodi lost the path of the
# last played item that is now being replayed (see playback.py's
# Player().play())
# Also see playqueue.py _compare_playqueues()
# Player().play()) Also see playqueue.py _compare_playqueues()
LOG.info('Detected re-start of playback of last item')
old = state.OLD_PLAYER_STATES[data['playlistid']]
kwargs = {
'plex_id': old['plex_id'],
'plex_type': old['plex_type'],
@ -240,6 +238,7 @@ class KodiMonitor(Monitor):
"""
pass
@LOCKER.lockthis
def _playlist_onclear(self, data):
"""
Called if a Kodi playlist is cleared. Example data dict:
@ -247,7 +246,11 @@ class KodiMonitor(Monitor):
u'playlistid': 1,
}
"""
pass
playqueue = PQ.PLAYQUEUES[data['playlistid']]
if not playqueue.is_pkc_clear():
playqueue.clear(kodi=False)
else:
LOG.debug('Detected PKC clear - ignoring')
def _get_ids(self, json_item):
"""

View file

@ -37,10 +37,6 @@ def playback_cleanup():
DU().downloadUrl(
'{server}/video/:/transcode/universal/stop',
parameters={'session': v.PKC_MACHINE_IDENTIFIER})
# Kodi will not clear the playqueue (because there is not really any)
# if there is only 1 item in it
if len(PQ.PLAYQUEUES[playerid].items) == 1:
PQ.PLAYQUEUES[playerid].clear()
# Reset the player's status
status = dict(state.PLAYSTATE)
# As all playback has halted, reset the players that have been active

View file

@ -48,6 +48,8 @@ class PlaylistObjectBaseclase(object):
self.plex_transient_token = None
# Need a hack for detecting swaps of elements
self.old_kodi_pl = []
# Workaround to avoid endless loops of detecting PL clears
self._clear_list = []
def __repr__(self):
"""
@ -67,6 +69,18 @@ class PlaylistObjectBaseclase(object):
answ += '\'%s\': %s, ' % (key, str(getattr(self, key)))
return answ + '\'items\': %s}}' % self.items
def is_pkc_clear(self):
"""
Returns True if PKC has cleared the Kodi playqueue just recently.
Then this clear will be ignored from now on
"""
try:
self._clear_list.pop()
except IndexError:
return False
else:
return True
def clear(self, kodi=True):
"""
Resets the playlist object to an empty playlist.
@ -76,6 +90,7 @@ class PlaylistObjectBaseclase(object):
# kodi monitor's on_clear method will only be called if there were some
# items to begin with
if kodi and self.kodi_pl.size() != 0:
self._clear_list.append(None)
self.kodi_pl.clear() # Clear Kodi playlist object
self.items = []
self.id = None