diff --git a/resources/lib/playback.py b/resources/lib/playback.py index ad4bea61..1faebebf 100644 --- a/resources/lib/playback.py +++ b/resources/lib/playback.py @@ -362,7 +362,7 @@ def process_indirect(key, offset, resolve=True): thread.start() -def play_xml(playqueue, xml): +def play_xml(playqueue, xml, offset=None): """ Play all items contained in the xml passed in. Called by Plex Companion. """ @@ -375,9 +375,24 @@ def play_xml(playqueue, xml): break else: startpos = 0 - # New thread to release this one sooner (e.g. harddisk spinning up) - thread = Thread(target=Player().play, - args=(playqueue.kodi_pl, None, False, startpos)) - thread.setDaemon(True) + thread = Thread(target=threaded_playback, + args=(playqueue.kodi_pl, startpos, offset)) LOG.info('Done play_xml, starting Kodi player at position %s', startpos) thread.start() + + +def threaded_playback(kodi_playlist, startpos, offset): + """ + Seek immediately after kicking off playback is not reliable. + """ + player = Player() + player.play(kodi_playlist, None, False, startpos) + if offset: + i = 0 + while not player.isPlaying(): + sleep(100) + i += 1 + if i > 100: + LOG.error('Could not seek to %s', offset) + return + js.seek_to(int(offset)) diff --git a/resources/lib/playqueue.py b/resources/lib/playqueue.py index 0109e073..36d45804 100644 --- a/resources/lib/playqueue.py +++ b/resources/lib/playqueue.py @@ -124,4 +124,4 @@ def update_playqueue_from_PMS(playqueue, return playqueue.repeat = 0 if not repeat else int(repeat) playqueue.plex_transient_token = transient_token - play_xml(playqueue, xml) + play_xml(playqueue, xml, offset)