From 19a22b9105acf08a4e7c92c3d9dc92b1e37b0622 Mon Sep 17 00:00:00 2001 From: Et0h Date: Mon, 16 Feb 2015 20:06:15 +0000 Subject: [PATCH] Autoplay countdown (+reduce autoplayCheck frequency) --- syncplay/client.py | 57 ++++++++++++++++++++++++++++++++++++++----- syncplay/constants.py | 9 ++++--- syncplay/messages.py | 3 +++ 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index d6d0b8c..40f8488 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -107,6 +107,9 @@ class SyncplayClient(object): self.autoPlay = False self.autoPlayThreshold = None + self.autoplayTimer = task.LoopingCall(self.autoplayCountdown) + self.autoplayTimeLeft = constants.AUTOPLAY_DELAY + self._warnings = self._WarningManager(self._player, self.userlist, self.ui, self) if constants.LIST_RELATIVE_CONFIGS and self._config.has_key('loadedRelativePaths') and self._config['loadedRelativePaths']: paths = "; ".join(self._config['loadedRelativePaths']) @@ -498,16 +501,50 @@ class SyncplayClient(object): self.autoplayCheck() def changeAutoPlayThrehsold(self, newThreshold): + oldAutoplayConditionsMet = self.autoplayConditionsMet() self.autoPlayThreshold = newThreshold - self.autoplayCheck() + newAutoplayConditionsMet = self.autoplayConditionsMet() + if oldAutoplayConditionsMet == False and newAutoplayConditionsMet == True: + self.autoplayCheck() def autoplayCheck(self): - if self.autoPlay and self.userlist.currentUser.canControl() and self.userlist.isReadinessSupported() and self.userlist.areAllUsersInRoomReady() and self.autoPlayThreshold and self.userlist.usersInRoomCount() >= self.autoPlayThreshold: + if self.autoplayConditionsMet(): + self.startAutoplayCountdown() + else: + self.stopAutoplayCountdown() + + def autoplayConditionsMet(self): + return self._playerPaused and self.autoPlay and self.userlist.currentUser.canControl() and self.userlist.isReadinessSupported() and self.userlist.areAllUsersInRoomReady() and self.autoPlayThreshold and self.userlist.usersInRoomCount() >= self.autoPlayThreshold + + def autoplayTimerIsRunning(self): + return self.autoplayTimer.running + + def startAutoplayCountdown(self): + if self.autoplayConditionsMet() and not self.autoplayTimer.running: + self.autoplayTimeLeft = constants.AUTOPLAY_DELAY + self.autoplayTimer.start(1) + + def stopAutoplayCountdown(self): + if self.autoplayTimer.running: + self.autoplayTimer.stop() + self.autoplayTimeLeft = constants.AUTOPLAY_DELAY + + def autoplayCountdown(self): + if not self.autoplayConditionsMet(): + self.stopAutoplayCountdown() + return + countdownMessage = u"{}{}{}".format(getMessage("all-users-ready").format(self.userlist.readyUserCount()),self._player.osdMessageSeparator, getMessage("autoplaying-notification").format(int(self.autoplayTimeLeft))) + self.ui.showOSDMessage(countdownMessage, 1, secondaryOSD=True) + if self.autoplayTimeLeft <= 0: self.setPaused(False) + self.stopAutoplayCountdown() + else: + self.autoplayTimeLeft -= 1 def resetAutoPlayState(self): self.autoPlay = False self.ui.updateAutoPlayState(False) + self.stopAutoplayCountdown() @requireMinServerVersion(constants.USER_READY_MIN_VERSION) def toggleReady(self, manuallyInitiated=True): @@ -616,6 +653,8 @@ class SyncplayClient(object): self.pausedTimer.start(constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL, True) def checkWarnings(self): + if self._client.autoplayConditionsMet(): + return self._checkIfYouReAloneInTheRoom(OSDOnly=False) self._checkRoomForSameFiles(OSDOnly=False) self.checkReadyStates() @@ -660,7 +699,7 @@ class SyncplayClient(object): self._displayReadySameWarning() def _displayReadySameWarning(self): - if not self._client._player: + if not self._client._player or self._client.autoplayTimerIsRunning(): return osdMessage = None fileDifferencesForRoom = self._userlist.getFileDifferencesForRoom() @@ -693,6 +732,8 @@ class SyncplayClient(object): pass def __displayPausedMessagesOnOSD(self): + if self._client.autoplayConditionsMet(): + return if self._client and self._client._player and self._client.getPlayerPaused(): self._checkRoomForSameFiles(OSDOnly=True) self.checkReadyStates() @@ -1055,7 +1096,8 @@ class UiManager(object): self.__ui.showUserList(currentUser, rooms) def showOSDMessage(self, message, duration=constants.OSD_DURATION, secondaryOSD=False): - if secondaryOSD and not constants.SHOW_OSD_WARNINGS: + autoplayConditionsMet = self._client.autoplayConditionsMet() + if secondaryOSD and not constants.SHOW_OSD_WARNINGS and not self._client.autoplayTimerIsRunning(): return if not self._client._player: return @@ -1063,7 +1105,10 @@ class UiManager(object): if not self._client._player.secondaryOSDSupported: if secondaryOSD: self.lastSecondaryOSDMessage = message - self.lastSecondaryOSDEndTime = time.time() + constants.NO_SECONDARY_OSD_WARNING_DURATION + if autoplayConditionsMet: + self.lastSecondaryOSDEndTime = time.time() + 1.0 + else: + self.lastSecondaryOSDEndTime = time.time() + constants.NO_SECONDARY_OSD_WARNING_DURATION if self.lastPrimaryOSDEndTime and time.time() < self.lastPrimaryOSDEndTime: message = u"{}{}{}".format(message, self._client._player.osdMessageSeparator, self.lastPrimaryOSDMessage) else: @@ -1071,7 +1116,7 @@ class UiManager(object): self.lastPrimaryOSDEndTime = time.time() + constants.OSD_DURATION if self.lastSecondaryOSDEndTime and time.time() < self.lastSecondaryOSDEndTime: message = u"{}{}{}".format(self.lastSecondaryOSDMessage, self._client._player.osdMessageSeparator, message) - self._client._player.displayMessage(message, duration * 1000, secondaryOSD) + self._client._player.displayMessage(message, int(duration * 1000), secondaryOSD) def setControllerStatus(self, username, isController): self.__ui.setControllerStatus(username, isController) diff --git a/syncplay/constants.py b/syncplay/constants.py index 682ca5e..3cab3d1 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -1,8 +1,8 @@ # You might want to change these DEFAULT_PORT = 8999 -OSD_DURATION = 3 -OSD_WARNING_MESSAGE_DURATION = 5 -NO_SECONDARY_OSD_WARNING_DURATION = 13 +OSD_DURATION = 3.0 +OSD_WARNING_MESSAGE_DURATION = 5.0 +NO_SECONDARY_OSD_WARNING_DURATION = 13.0 MPC_OSD_POSITION = 1 #Right corner, 1 for left MPLAYER_OSD_LEVEL = 1 UI_TIME_FORMAT = "[%X] " @@ -34,7 +34,7 @@ MINIMUM_REWIND_THRESHOLD = 3 DEFAULT_FASTFORWARD_THRESHOLD = 5 MINIMUM_FASTFORWARD_THRESHOLD = 4 FASTFORWARD_EXTRA_TIME = 0.25 -FASTFORWARD_RESET_THRESHOLD = 3 +FASTFORWARD_RESET_THRESHOLD = 3.0 FASTFORWARD_BEHIND_THRESHOLD = 1.75 SEEK_THRESHOLD = 1 SLOWDOWN_RATE = 0.95 @@ -46,6 +46,7 @@ PROTOCOL_TIMEOUT = 12.5 RECONNECT_RETRIES = 10 SERVER_STATE_INTERVAL = 1 WARNING_OSD_MESSAGES_LOOP_INTERVAL = 1 +AUTOPLAY_DELAY = 3.0 SYNC_ON_PAUSE = True # Client seek to global position - subtitles may disappear on some media players #Usually there's no need to adjust these LAST_PAUSED_DIFF_THRESHOLD = 2 diff --git a/syncplay/messages.py b/syncplay/messages.py index 35c1839..8c0d207 100755 --- a/syncplay/messages.py +++ b/syncplay/messages.py @@ -36,6 +36,7 @@ en = { "not-all-ready" : u"Not ready: {}", # Usernames "all-users-ready" : u"Everyone is ready ({} users)", #Number of ready users "ready-to-unpause-notification" : u"You are now set as ready - unpause again to unpause", + "autoplaying-notification" : u"Auto-playing in {}...", "identifying-as-controller-notification" : u"Identifying as room operator with password '{}'...", "failed-to-identify-as-controller-notification" : u"<{}> failed to identify as a room operator.", @@ -381,6 +382,7 @@ ru = { "not-all-ready" : u"Not ready: {}", # Usernames # TODO: Translate into Russian "all-users-ready" : u"Everyone is ready ({} users)", #Number of ready users # TODO: Translate into Russian "ready-to-unpause-notification" : u"You are now set as ready - unpause again to unpause", # TODO: Translate into Russian + "autoplaying-notification" : u"Auto-playing in {}...", # TODO: Translate into Russian "identifying-as-controller-notification" : u"Identifying as room operator with password '{}'...", # TODO: Translate into Russian "failed-to-identify-as-controller-notification" : u"<{}> failed to identify as a room operator.", # TODO: Translate into Russian @@ -727,6 +729,7 @@ de = { "not-all-ready" : u"Not ready: {}", # Usernames # TODO: Translate into German "all-users-ready" : u"Everyone is ready ({} users)", #Number of ready users # TODO: Translate into German "ready-to-unpause-notification" : u"You are now set as ready - unpause again to unpause", # TODO: Translate into German + "autoplaying-notification" : u"Auto-playing in {}...", # TODO: Translate into German "identifying-as-controller-notification" : u"Identifiziere als Raumleiter mit Passwort '{}'...", # TODO: find a better translation to "room operator" "failed-to-identify-as-controller-notification" : u"<{}> konnte sich nicht als Raumleiter identifizieren.",