From 56554489193de16fc19c14054ec0a1e7a499d789 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 12 Jul 2016 16:55:10 +1000 Subject: [PATCH] explictly use utf8 when talking to mplayer universal_newlines uses system locale which is ascii on osx unless LC_CTYPE/LANG is set to utf8, so we need to be explicit about the encoding we want instead we also lose line buffering, so we have to explicitly flush --- anki/sound.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/anki/sound.py b/anki/sound.py index 337a2c545..e947a4f8f 100644 --- a/anki/sound.py +++ b/anki/sound.py @@ -94,6 +94,7 @@ class MplayerMonitor(threading.Thread): if mplayerClear and self.mplayer: try: self.mplayer.stdin.write("stop\n") + self.mplayer.stdin.flush() except: # mplayer quit by user (likely video) self.deadPlayers.append(self.mplayer) @@ -111,18 +112,20 @@ class MplayerMonitor(threading.Thread): continue if mplayerClear: mplayerClear = False - extra = "" + extra = b"" else: - extra = " 1" - cmd = 'loadfile "%s"%s\n' % (item, extra) + extra = b" 1" + cmd = b'loadfile "%s"%s\n' % (item.encode("utf8"), extra) try: self.mplayer.stdin.write(cmd) + self.mplayer.stdin.flush() except: # mplayer has quit and needs restarting self.deadPlayers.append(self.mplayer) self.mplayer = None self.startProcess() self.mplayer.stdin.write(cmd) + self.mplayer.stdin.flush() # if we feed mplayer too fast it loses files time.sleep(1) # wait() on finished processes. we don't want to block on the @@ -140,6 +143,7 @@ class MplayerMonitor(threading.Thread): return try: self.mplayer.stdin.write("quit\n") + self.mplayer.stdin.flush() self.deadPlayers.append(self.mplayer) except: pass @@ -154,7 +158,7 @@ class MplayerMonitor(threading.Thread): self.mplayer = subprocess.Popen( cmd, startupinfo=si, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, - universal_newlines=True, bufsize=1, env=env) + env=env) except OSError: mplayerEvt.clear() raise Exception("Did you install mplayer?")