Fix some rewind issues relating to file loads / playlist changes (#698)

* Re-introduce rewind double check

* Major re-work to playlist changing/advancement (#683 & #618)

* Remove stray print

* Fix mpv.net 'auto load folder' playlist advancement bug

* Update client.py to remove commented-out code
This commit is contained in:
Etoh 2024-11-18 20:05:51 +00:00 committed by GitHub
parent dd3884b3c8
commit 6c632e3159
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 7 deletions

View File

@ -83,6 +83,9 @@ class SyncplayClient(object):
self.lastRewindTime = None
self.lastUpdatedFileTime = None
self.lastAdvanceTime = None
self.fileOpenBeforeChangingPlaylistIndex = None
self.waitingToLoadNewfile = False
self.waitingToLoadNewfileSince = None
self.lastConnectTime = None
self.lastSetRoomTime = None
self.hadFirstPlaylistIndex = False
@ -248,15 +251,23 @@ class SyncplayClient(object):
if self._lastGlobalUpdate:
self._lastPlayerUpdate = time.time()
if (pauseChange or seeked) and self._protocol:
if self.recentlyRewound() or self._recentlyAdvanced():
self._protocol.sendState(self._globalPosition, self.getPlayerPaused(), False, None, True)
return
if seeked:
self.playerPositionBeforeLastSeek = self.getGlobalPosition()
self._protocol.sendState(self.getPlayerPosition(), self.getPlayerPaused(), seeked, None, True)
def prepareToChangeToNewPlaylistItemAndRewind(self):
self.ui.showDebugMessage("Preparing to change to new playlist index and rewind...")
self.fileOpenBeforeChangingPlaylistIndex = self.userlist.currentUser.file["path"] if self.userlist.currentUser.file else None
self.waitingToLoadNewfile = True
self.waitingToLoadNewfileSince = time.time()
def prepareToAdvancePlaylist(self):
if self.playlist.canSwitchToNextPlaylistIndex():
self.ui.showDebugMessage("Preparing to advance playlist...")
self.lastAdvanceTime = time.time()
self._protocol.sendState(0, True, True, None, True)
else:
self.ui.showDebugMessage("Not preparing to advance playlist because the next file cannot be switched to")
@ -1847,7 +1858,7 @@ class SyncplayPlaylist():
if self._client.playerIsNotReady():
if not self.addedChangeListCallback:
self.addedChangeListCallback = True
self._client.addPlayerReadyCallback(lambda x: self.changeToPlaylistIndex(index, username))
self._client.addPlayerReadyCallback(lambda x: self.changeToPlaylistIndex(index, username, resetPosition))
return
try:
filename = self._playlist[index]
@ -1863,10 +1874,22 @@ class SyncplayPlaylist():
self._playlistIndex = index
if username is None:
if self._client.isConnectedAndInARoom() and self._client.sharedPlaylistIsEnabled():
if resetPosition:
self._client.rewindFile()
self._client.setPlaylistIndex(index)
filename = self._playlist[index]
self._ui.setPlaylistIndexFilename(filename)
if resetPosition:
self._ui.showDebugMessage("Pausing due to index change")
state = {}
state["playstate"] = {}
state["playstate"]["position"] = 0
state["playstate"]["paused"] = True
self._client.lastAdvanceTime = time.time()
self._client._protocol.sendMessage({"State": state})
self._playerPaused = True
self._client.autoplayCheck()
elif index is not None:
filename = self._playlist[index]
self._ui.setPlaylistIndexFilename(filename)
self._ui.showMessage(getMessage("playlist-selection-changed-notification").format(username))
self.switchToNewPlaylistIndex(index, resetPosition=resetPosition)
@ -1892,7 +1915,12 @@ class SyncplayPlaylist():
self.queuedIndexFilename = self._playlist[index]
except:
self.queuedIndexFilename = None
self._ui.showDebugMessage("Failed to find index {} in plauylist".format(index))
self._ui.showDebugMessage("Failed to find index {} in playlist".format(index))
if resetPosition and index is not None:
filename = self._playlist[index]
if (not utils.isURL(filename)) or self._client.isURITrusted(filename):
self._client.prepareToChangeToNewPlaylistItemAndRewind()
self._lastPlaylistIndexChange = time.time()
if self._client.playerIsNotReady():
self._client.addPlayerReadyCallback(lambda x: self.switchToNewPlaylistIndex(index, resetPosition))
@ -1913,7 +1941,7 @@ class SyncplayPlaylist():
else:
path = self._client.fileSwitch.findFilepath(filename, highPriority=True)
if path:
self._client.openFile(path, resetPosition)
self._client.openFile(path, resetPosition=resetPosition)
else:
self._ui.showErrorMessage(getMessage("cannot-find-file-for-playlist-switch-error").format(filename))
return

View File

@ -111,7 +111,7 @@ FOLDER_SEARCH_WARNING_THRESHOLD = 2.0 # Secs - how long until a warning saying h
FOLDER_SEARCH_DOUBLE_CHECK_INTERVAL = 30.0 # Secs - Frequency of updating cache
# Usually there's no need to adjust these
DOUBLE_CHECK_REWIND = False
DOUBLE_CHECK_REWIND = True
LAST_PAUSED_DIFF_THRESHOLD = 2
FILENAME_STRIP_REGEX = r"[-~_\.\[\](): ]"
CONTROL_PASSWORD_STRIP_REGEX = r"[^a-zA-Z0-9\-]"
@ -273,6 +273,7 @@ MPV_ARGS = {'force-window': 'yes',
'term-playing-msg': '<SyncplayUpdateFile>\nANS_filename=${filename}\nANS_length=${=duration:${=length:0}}\nANS_path=${path}\n</SyncplayUpdateFile>',
'keep-open-pause': 'yes'
}
MPV_NET_EXTRA_ARGS = { 'auto-load-folder': 'no' }
IINA_PROPERTIES = {'geometry': '25%+100+100',
'idle': 'yes',

View File

@ -8,6 +8,7 @@ class MpvnetPlayer(MpvPlayer):
@staticmethod
def run(client, playerPath, filePath, args):
args.extend(constants.MPV_NET_EXTRA_ARGS)
constants.MPV_NEW_VERSION = True
constants.MPV_OSC_VISIBILITY_CHANGE_VERSION = True
return MpvnetPlayer(client, MpvnetPlayer.getExpandedPath(playerPath), filePath, args)