From 1964d25e9666a9afa5286640394dc302a43eef06 Mon Sep 17 00:00:00 2001 From: Et0h Date: Mon, 7 Dec 2015 21:55:23 +0000 Subject: [PATCH] Reduce MPC problems when file change takes too long --- syncplay/players/mpc.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/syncplay/players/mpc.py b/syncplay/players/mpc.py index 8b2c938..6ab1452 100644 --- a/syncplay/players/mpc.py +++ b/syncplay/players/mpc.py @@ -418,20 +418,22 @@ class MPCHCAPIPlayer(BasePlayer): self._mpcApi.askForCurrentPosition() self.__positionUpdate.wait(constants.MPC_LOCK_WAIT_TIME) return self._mpcApi.lastFilePosition - - @retry(MpcHcApi.PlayerNotReadyException, constants.MPC_MAX_RETRIES, constants.MPC_RETRY_WAIT_TIME, 1) + def askForStatus(self): - if self._mpcApi.filePlaying and self.__preventAsking.wait(0) and self.__fileUpdate.acquire(0): - self.__fileUpdate.release() - position = self.__getPosition() - paused = self._mpcApi.isPaused() - position = float(position) - if self.__preventAsking.wait(0) and self.__fileUpdate.acquire(0): - self.__client.updatePlayerStatus(paused, position) + try: + if self._mpcApi.filePlaying and self.__preventAsking.wait(0) and self.__fileUpdate.acquire(0): self.__fileUpdate.release() - return - self.__echoGlobalStatus() - + position = self.__getPosition() + paused = self._mpcApi.isPaused() + position = float(position) + if self.__preventAsking.wait(0) and self.__fileUpdate.acquire(0): + self.__client.updatePlayerStatus(paused, position) + self.__fileUpdate.release() + else: + self.__echoGlobalStatus() + except MpcHcApi.PlayerNotReadyException: + self.__echoGlobalStatus() + def __echoGlobalStatus(self): self.__client.updatePlayerStatus(self.__client.getGlobalPaused(), self.__client.getGlobalPosition())