Use 1 PKC xbmc.player instance

This commit is contained in:
tomkat83 2016-07-23 18:06:47 +02:00
parent d6c14d0aa4
commit eff7d7b68b
5 changed files with 25 additions and 18 deletions

View file

@ -21,7 +21,7 @@ class PlexCompanion(threading.Thread):
""" """
Initialize with a Queue for callbacks Initialize with a Queue for callbacks
""" """
def __init__(self): def __init__(self, player=None):
self.logMsg("----===## Starting PlexCompanion ##===----", 1) self.logMsg("----===## Starting PlexCompanion ##===----", 1)
self.settings = settings.getSettings() self.settings = settings.getSettings()
@ -35,6 +35,9 @@ class PlexCompanion(threading.Thread):
self.queueId = None self.queueId = None
self.playlist = None self.playlist = None
# kodi player instance
self.player = player
threading.Thread.__init__(self) threading.Thread.__init__(self)
def _getStartItem(self, string): def _getStartItem(self, string):
@ -82,11 +85,13 @@ class PlexCompanion(threading.Thread):
self.queueId = None self.queueId = None
if self.playlist is None: if self.playlist is None:
if data.get('type') == 'music': if data.get('type') == 'music':
self.playlist = playlist.Playlist('music') self.playlist = playlist.Playlist('music',
player=self.player)
elif data.get('type') == 'video': elif data.get('type') == 'video':
self.playlist = playlist.Playlist('video') self.playlist = playlist.Playlist('video',
player=self.player)
else: else:
self.playlist = playlist.Playlist() self.playlist = playlist.Playlist(player=self.player)
if queueId != self.queueId: if queueId != self.queueId:
self.logMsg('New playlist received, updating!', 1) self.logMsg('New playlist received, updating!', 1)
self.queueId = queueId self.queueId = queueId

View file

@ -20,10 +20,10 @@ from PlexFunctions import scrobble
@utils.logging @utils.logging
class KodiMonitor(xbmc.Monitor): class KodiMonitor(xbmc.Monitor):
def __init__(self): def __init__(self, player=None):
self.doUtils = downloadutils.DownloadUtils().downloadUrl self.doUtils = downloadutils.DownloadUtils().downloadUrl
self.xbmcplayer = xbmc.Player() self.xbmcplayer = player
xbmc.Monitor.__init__(self) xbmc.Monitor.__init__(self)
self.logMsg("Kodi monitor started.", 1) self.logMsg("Kodi monitor started.", 1)

View file

@ -1549,9 +1549,9 @@ class LibrarySync(Thread):
with itemFkt() as Fkt: with itemFkt() as Fkt:
Fkt.updatePlaystate(item) Fkt.updatePlaystate(item)
def run(self): def run(self, player=None):
try: try:
self.run_internal() self.run_internal(player)
except Exception as e: except Exception as e:
utils.window('plex_dbScan', clear=True) utils.window('plex_dbScan', clear=True)
self.logMsg('LibrarySync thread crashed', -1) self.logMsg('LibrarySync thread crashed', -1)
@ -1563,7 +1563,7 @@ class LibrarySync(Thread):
self.__language__(39400)) self.__language__(39400))
raise raise
def run_internal(self): def run_internal(self, player=None):
# Re-assign handles to have faster calls # Re-assign handles to have faster calls
window = utils.window window = utils.window
settings = utils.settings settings = utils.settings
@ -1582,7 +1582,7 @@ class LibrarySync(Thread):
lastProcessing = 0 lastProcessing = 0
oneDay = 60*60*24 oneDay = 60*60*24
xbmcplayer = xbmc.Player() xbmcplayer = player
queue = self.queue queue = self.queue

View file

@ -21,7 +21,7 @@ class Playlist():
""" """
Initiate with Playlist(typus='video' or 'music') Initiate with Playlist(typus='video' or 'music')
""" """
def __init__(self, typus=None): def __init__(self, typus=None, player=None):
self.userid = utils.window('currUserId') self.userid = utils.window('currUserId')
self.server = utils.window('pms_server') self.server = utils.window('pms_server')
# Construct the Kodi playlist instance # Construct the Kodi playlist instance
@ -38,7 +38,8 @@ class Playlist():
self.typus = None self.typus = None
if self.playlist is not None: if self.playlist is not None:
self.playlistId = self.playlist.getPlayListId() self.playlistId = self.playlist.getPlayListId()
self.player = xbmc.Player() # kodi player instance
self.player = player
# "interal" PKC playlist # "interal" PKC playlist
self.items = [] self.items = []

View file

@ -140,7 +140,6 @@ class Service():
ws = wsc.WebSocket(queue) ws = wsc.WebSocket(queue)
library = librarysync.LibrarySync(queue) library = librarysync.LibrarySync(queue)
kplayer = player.Player() kplayer = player.Player()
xplayer = xbmc.Player()
plx = PlexAPI.PlexAPI() plx = PlexAPI.PlexAPI()
# Sync and progress report # Sync and progress report
@ -167,11 +166,11 @@ class Service():
# Verify if user is set and has access to the server # Verify if user is set and has access to the server
if (user.currUser is not None) and user.HasAccess: if (user.currUser is not None) and user.HasAccess:
# If an item is playing # If an item is playing
if xplayer.isPlaying(): if kplayer.isPlaying():
try: try:
# Update and report progress # Update and report progress
playtime = xplayer.getTime() playtime = kplayer.getTime()
totalTime = xplayer.getTotalTime() totalTime = kplayer.getTotalTime()
currentFile = kplayer.currentFile currentFile = kplayer.currentFile
# Update positionticks # Update positionticks
@ -209,7 +208,8 @@ class Service():
time=2000, time=2000,
sound=False) sound=False)
# Start monitoring kodi events # Start monitoring kodi events
self.kodimonitor_running = kodimonitor.KodiMonitor() self.kodimonitor_running = kodimonitor.KodiMonitor(
player=kplayer)
# Start the Websocket Client # Start the Websocket Client
if not self.websocket_running: if not self.websocket_running:
@ -222,7 +222,8 @@ class Service():
# Start the Plex Companion thread # Start the Plex Companion thread
if not self.plexCompanion_running: if not self.plexCompanion_running:
self.plexCompanion_running = True self.plexCompanion_running = True
plexCompanion = PlexCompanion.PlexCompanion() plexCompanion = PlexCompanion.PlexCompanion(
player=kplayer)
plexCompanion.start() plexCompanion.start()
else: else:
if (user.currUser is None) and self.warn_auth: if (user.currUser is None) and self.warn_auth: