Attempt to fix widget playback
This commit is contained in:
parent
40d670d002
commit
4be376faac
1 changed files with 46 additions and 21 deletions
|
@ -5,7 +5,7 @@ from logging import getLogger
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
|
|
||||||
from xbmc import Player, sleep
|
from xbmc import Player, sleep, getCondVisibility
|
||||||
|
|
||||||
from PlexAPI import API
|
from PlexAPI import API
|
||||||
from PlexFunctions import GetPlexMetadata, init_plex_playqueue
|
from PlexFunctions import GetPlexMetadata, init_plex_playqueue
|
||||||
|
@ -47,8 +47,10 @@ def playback_triage(plex_id=None, plex_type=None, path=None, resolve=True):
|
||||||
the first pass - e.g. if you're calling this function from the original
|
the first pass - e.g. if you're calling this function from the original
|
||||||
service.py Python instance
|
service.py Python instance
|
||||||
"""
|
"""
|
||||||
LOG.info('playback_triage called with plex_id %s, plex_type %s, path %s',
|
# Widget playback? Pain in the butt...
|
||||||
plex_id, plex_type, path)
|
widget = getCondVisibility('Window.IsActive(home)')
|
||||||
|
LOG.info('playback_triage called with plex_id %s, plex_type %s, path %s,'
|
||||||
|
' widget playback: %s', plex_id, plex_type, path, widget)
|
||||||
if not state.AUTHENTICATED:
|
if not state.AUTHENTICATED:
|
||||||
LOG.error('Not yet authenticated for PMS, abort starting playback')
|
LOG.error('Not yet authenticated for PMS, abort starting playback')
|
||||||
if resolve is True:
|
if resolve is True:
|
||||||
|
@ -68,18 +70,18 @@ def playback_triage(plex_id=None, plex_type=None, path=None, resolve=True):
|
||||||
playqueue.items[pos]
|
playqueue.items[pos]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# Release our default.py before starting our own Kodi player instance
|
# Release our default.py before starting our own Kodi player instance
|
||||||
if resolve is True:
|
if resolve is True and not widget:
|
||||||
state.PKC_CAUSED_STOP = True
|
state.PKC_CAUSED_STOP = True
|
||||||
result = Playback_Successful()
|
result = Playback_Successful()
|
||||||
result.listitem = PKC_ListItem(path='PKC_Dummy_Path_Which_Fails')
|
result.listitem = PKC_ListItem(path='PKC_Dummy_Path_Which_Fails')
|
||||||
pickle_me(result)
|
pickle_me(result)
|
||||||
playback_init(plex_id, plex_type, playqueue)
|
playback_init(plex_id, plex_type, playqueue, widget)
|
||||||
else:
|
else:
|
||||||
# kick off playback on second pass
|
# kick off playback on second pass
|
||||||
conclude_playback(playqueue, pos)
|
conclude_playback(playqueue, pos)
|
||||||
|
|
||||||
|
|
||||||
def playback_init(plex_id, plex_type, playqueue):
|
def playback_init(plex_id, plex_type, playqueue, widget):
|
||||||
"""
|
"""
|
||||||
Playback setup if Kodi starts playing an item for the first time.
|
Playback setup if Kodi starts playing an item for the first time.
|
||||||
"""
|
"""
|
||||||
|
@ -119,12 +121,31 @@ def playback_init(plex_id, plex_type, playqueue):
|
||||||
# Should already be empty, but just in case
|
# Should already be empty, but just in case
|
||||||
PL.get_playlist_details_from_xml(playqueue, xml)
|
PL.get_playlist_details_from_xml(playqueue, xml)
|
||||||
stack = _prep_playlist_stack(xml)
|
stack = _prep_playlist_stack(xml)
|
||||||
|
if widget:
|
||||||
|
# Need to use setResolvedUrl when using widgets :-(
|
||||||
|
# Grab the very first item of our stack
|
||||||
|
stack_item = stack.pop(0)
|
||||||
|
# Get the PKC playlist element
|
||||||
|
item = PL.playlist_item_from_xml(playqueue,
|
||||||
|
stack_item['xml_video_element'],
|
||||||
|
stack_item['kodi_id'],
|
||||||
|
stack_item['kodi_type'])
|
||||||
|
item.playcount = stack_item['playcount']
|
||||||
|
item.offset = stack_item['offset']
|
||||||
|
item.part = stack_item['part']
|
||||||
|
item.id = stack_item['id']
|
||||||
|
item.force_transcode = state.FORCE_TRANSCODE
|
||||||
|
# Only add our very first item to our playqueue
|
||||||
|
playqueue.items.append(item)
|
||||||
|
# Conclude the playback with setResolvedUrl
|
||||||
|
LOG.debug('Start concluding playback for 1st widget element')
|
||||||
|
conclude_playback(playqueue, 0)
|
||||||
|
LOG.debug('Add remaining items to playqueues for widget playback')
|
||||||
|
_process_stack(playqueue, stack)
|
||||||
|
else:
|
||||||
# Sleep a bit to let setResolvedUrl do its thing - bit ugly
|
# Sleep a bit to let setResolvedUrl do its thing - bit ugly
|
||||||
sleep(200)
|
sleep(200)
|
||||||
_process_stack(playqueue, stack)
|
_process_stack(playqueue, stack)
|
||||||
# Reset some playback variables
|
|
||||||
state.CONTEXT_MENU_PLAY = False
|
|
||||||
state.FORCE_TRANSCODE = False
|
|
||||||
# New thread to release this one sooner (e.g. harddisk spinning up)
|
# New thread to release this one sooner (e.g. harddisk spinning up)
|
||||||
thread = Thread(target=Player().play,
|
thread = Thread(target=Player().play,
|
||||||
args=(playqueue.kodi_pl, ))
|
args=(playqueue.kodi_pl, ))
|
||||||
|
@ -134,9 +155,13 @@ def playback_init(plex_id, plex_type, playqueue):
|
||||||
# caches paths like our plugin://pkc. If we use Player().play() between
|
# caches paths like our plugin://pkc. If we use Player().play() between
|
||||||
# 2 consecutive startups of exactly the same Kodi library item, Kodi's
|
# 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
|
# 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
|
# plugin://pkc will be lost; Kodi will try to startup playback for an
|
||||||
# path: log entry is "CGUIWindowVideoBase::OnPlayMedia <missing path>"
|
# empty path: log entry is "CGUIWindowVideoBase::OnPlayMedia <missing
|
||||||
|
# path>"
|
||||||
thread.start()
|
thread.start()
|
||||||
|
# Reset some playback variables
|
||||||
|
state.CONTEXT_MENU_PLAY = False
|
||||||
|
state.FORCE_TRANSCODE = False
|
||||||
|
|
||||||
|
|
||||||
def _prep_playlist_stack(xml):
|
def _prep_playlist_stack(xml):
|
||||||
|
|
Loading…
Reference in a new issue