Skip to content

Commit

Permalink
Fixes VLC close issue on macOS (Syncplay#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertosottile committed Oct 15, 2017
1 parent 846d7f7 commit 32882ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions syncplay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
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"]
Expand Down
22 changes: 19 additions & 3 deletions syncplay/players/vlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -381,7 +383,12 @@ def _usevlcintf(vlcIntfPath, vlcIntfUserPath):
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")
Expand Down Expand Up @@ -427,6 +434,15 @@ def handle_close(self):
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))
Expand Down

0 comments on commit 32882ee

Please sign in to comment.