Fix repeated playback of same resumable item

This commit is contained in:
croneter 2018-01-26 09:47:58 +01:00
parent cfff75926a
commit 6e6fbadb02
3 changed files with 30 additions and 12 deletions

View file

@ -209,18 +209,24 @@ class KodiMonitor(Monitor):
# Kodi remembers the last setResolvedUrl - which is empty in our case # Kodi remembers the last setResolvedUrl - which is empty in our case
kodi_item = js.get_item(data['playlistid']) kodi_item = js.get_item(data['playlistid'])
LOG.debug('kodi_item: %s', kodi_item) LOG.debug('kodi_item: %s', kodi_item)
# if kodi_item.get('file') == '': if (state.RESUMABLE is True and
# LOG.info('Detected re-start of playback of last item') data['position'] == 0 and
# old = state.OLD_PLAYER_STATES[data['playlistid']] data['item'].get('title') is not None and
# kwargs = { getCondVisibility('Window.IsVisible(MyVideoNav.xml)')):
# 'plex_id': old['plex_id'], # Hack we need for RESUMABLE items because Kodi lost the path of the
# 'plex_type': old['plex_type'], # last played item that is now being replayed (see playback.py's
# 'path': old['file'], # Player().play())
# 'resolve': False LOG.info('Detected re-start of playback of last item')
# } old = state.OLD_PLAYER_STATES[data['playlistid']]
# thread = Thread(target=playback_triage, kwargs=kwargs) kwargs = {
# thread.start() 'plex_id': old['plex_id'],
# return 'plex_type': old['plex_type'],
'path': old['file'],
'resolve': False
}
thread = Thread(target=playback_triage, kwargs=kwargs)
thread.start()
return
# Have we initiated the playqueue already? If not, ignore this # Have we initiated the playqueue already? If not, ignore this
if not playqueue.items: if not playqueue.items:
LOG.debug('Playqueue not initiated - ignoring') LOG.debug('Playqueue not initiated - ignoring')
@ -414,6 +420,8 @@ class SpecialMonitor(Thread):
if (not is_playing and if (not is_playing and
getCondVisibility('Window.IsVisible(DialogContextMenu.xml)') and getCondVisibility('Window.IsVisible(DialogContextMenu.xml)') and
getInfoLabel('Control.GetLabel(1002)') == getLocalizedString(12021)): getInfoLabel('Control.GetLabel(1002)') == getLocalizedString(12021)):
# Remember that the item IS indeed resumable
state.RESUMABLE = True
control = int(Window(10106).getFocusId()) control = int(Window(10106).getFocusId())
if control == 1002: if control == 1002:
# Start from beginning # Start from beginning

View file

@ -173,6 +173,12 @@ def playback_init(plex_id, plex_type, playqueue):
args=(playqueue.kodi_pl, )) args=(playqueue.kodi_pl, ))
thread.setDaemon(True) thread.setDaemon(True)
LOG.info('Done initializing PKC playback, starting Kodi player') LOG.info('Done initializing PKC playback, starting Kodi player')
# By design, PKC will start Kodi playback using Player().play(). Kodi
# caches paths like our plugin://pkc. If we use Player().play() between
# 2 consecutive startups of exactly the same Kodi library item, Kodi's
# cache will have been flushed for some reason. Hence the 2nd call for
# plugin://pkc will be lost; Kodi will try to startup playback for an empty
# path: log entry is "CGUIWindowVideoBase::OnPlayMedia <missing path>"
thread.start() thread.start()
@ -287,6 +293,8 @@ def conclude_playback(playqueue, pos):
LOG.info('Resuming playback at %s', item.offset) LOG.info('Resuming playback at %s', item.offset)
listitem.setProperty('StartOffset', str(item.offset)) listitem.setProperty('StartOffset', str(item.offset))
listitem.setProperty('resumetime', str(item.offset)) listitem.setProperty('resumetime', str(item.offset))
# Reset the resumable flag
state.RESUMABLE = False
result.listitem = listitem result.listitem = listitem
pickle_me(result) pickle_me(result)
LOG.info('Done concluding playback') LOG.info('Done concluding playback')

View file

@ -134,6 +134,8 @@ PLAYSTATE = {
# paths for playback (since we're not receiving a Kodi id) # paths for playback (since we're not receiving a Kodi id)
PLEX_IDS = {} PLEX_IDS = {}
PLAYED_INFO = {} PLAYED_INFO = {}
# Flag whether Kodi item where the playback is being started is even resumable
RESUMABLE = False
# Set by SpecialMonitor - did user choose to resume playback or start from the # Set by SpecialMonitor - did user choose to resume playback or start from the
# beginning? # beginning?
RESUME_PLAYBACK = False RESUME_PLAYBACK = False