From 2f24882426fce11d12ca3f35d3108cf280aa55b2 Mon Sep 17 00:00:00 2001 From: alby128 Date: Sun, 15 Oct 2017 17:11:36 +0200 Subject: [PATCH] Fixes VLC close issue on macOS (#83) --- syncplay/constants.py | 1 + syncplay/players/vlc.py | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/syncplay/constants.py b/syncplay/constants.py index 69a1123..7b4b3f3 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -172,6 +172,7 @@ MPV_SLAVE_ARGS_NEW = ['--term-playing-msg=\nANS_filename=${f MPV_NEW_VERSION = False VLC_SLAVE_ARGS = ['--extraintf=luaintf', '--lua-intf=syncplay', '--no-quiet', '--no-input-fast-seek', '--play-and-pause', '--start-time=0'] +VLC_SLAVE_OSX_ARGS = ['--verbose=2', '--no-file-logging'] VLC_SLAVE_NONOSX_ARGS = ['--no-one-instance', '--no-one-instance-when-started-from-file'] MPV_SUPERSEDE_IF_DUPLICATE_COMMANDS = ["no-osd set time-pos ", "loadfile "] MPV_REMOVE_BOTH_IF_DUPLICATE_COMMANDS = ["cycle pause"] diff --git a/syncplay/players/vlc.py b/syncplay/players/vlc.py index f3571ab..c1228a0 100644 --- a/syncplay/players/vlc.py +++ b/syncplay/players/vlc.py @@ -20,8 +20,10 @@ class VlcPlayer(BasePlayer): RE_ANSWER = re.compile(constants.VLC_ANSWER_REGEX) SLAVE_ARGS = constants.VLC_SLAVE_ARGS - if not sys.platform.startswith('darwin'): - SLAVE_ARGS.extend(constants.VLC_SLAVE_NONOSX_ARGS) + if sys.platform.startswith('darwin'): + SLAVE_ARGS.extend(constants.VLC_SLAVE_OSX_ARGS) + else: + SLAVE_ARGS.extend(constants.VLC_SLAVE_NONOSX_ARGS) vlcport = random.randrange(constants.VLC_MIN_PORT, constants.VLC_MAX_PORT) if (constants.VLC_MIN_PORT < constants.VLC_MAX_PORT) else constants.VLC_MIN_PORT def __init__(self, client, playerPath, filePath, args): @@ -381,7 +383,12 @@ class VlcPlayer(BasePlayer): playerController._client.ui.showErrorMessage( getMessage("media-player-error").format(line), True) break - self.__process.stderr = None + if not sys.platform.startswith('darwin'): + self.__process.stderr = None + else: + vlcoutputthread = threading.Thread(target = self.handle_vlcoutput, args=()) + vlcoutputthread.setDaemon(True) + vlcoutputthread.start() threading.Thread.__init__(self, name="VLC Listener") asynchat.async_chat.__init__(self) self.set_terminator("\n") @@ -427,6 +434,15 @@ class VlcPlayer(BasePlayer): asynchat.async_chat.handle_close(self) self.__playerController.drop(getMessage("vlc-failed-connection").format(constants.VLC_MIN_VERSION)) + def handle_vlcoutput(self): + out = self.__process.stderr + for line in iter(out.readline, ''): + if '[syncplay] core interface debug: removing module' in line: + self.__playerController.drop() + break + out.close() + + def found_terminator(self): self.vlcHasResponded = True self.__playerController.lineReceived("".join(self._ibuffer))