fix audio getting stuck (2/2)

This commit is contained in:
Damien Elmes 2020-03-15 09:34:04 +10:00
parent f30853f5ed
commit 0ecc189a9b
2 changed files with 17 additions and 27 deletions

View file

@ -217,10 +217,6 @@ def retryWait(proc: subprocess.Popen) -> int:
########################################################################## ##########################################################################
class PlayerInterrupted(Exception):
pass
class SimpleProcessPlayer(Player): # pylint: disable=abstract-method class SimpleProcessPlayer(Player): # pylint: disable=abstract-method
"A player that invokes a new process for each tag to play." "A player that invokes a new process for each tag to play."
@ -231,7 +227,6 @@ class SimpleProcessPlayer(Player): # pylint: disable=abstract-method
self._taskman = taskman self._taskman = taskman
self._terminate_flag = False self._terminate_flag = False
self._process: Optional[subprocess.Popen] = None self._process: Optional[subprocess.Popen] = None
self._lock = threading.Lock()
def play(self, tag: AVTag, on_done: OnDoneCallback) -> None: def play(self, tag: AVTag, on_done: OnDoneCallback) -> None:
self._terminate_flag = False self._terminate_flag = False
@ -260,7 +255,6 @@ class SimpleProcessPlayer(Player): # pylint: disable=abstract-method
) )
while True: while True:
with self._lock:
# should we abort playing? # should we abort playing?
if self._terminate_flag: if self._terminate_flag:
self._process.terminate() self._process.terminate()

View file

@ -37,7 +37,7 @@ from anki import hooks
from anki.sound import AVTag, TTSTag from anki.sound import AVTag, TTSTag
from anki.utils import checksum, isWin, tmpdir from anki.utils import checksum, isWin, tmpdir
from aqt import gui_hooks from aqt import gui_hooks
from aqt.sound import OnDoneCallback, PlayerInterrupted, SimpleProcessPlayer from aqt.sound import OnDoneCallback, SimpleProcessPlayer
@dataclass @dataclass
@ -234,11 +234,7 @@ class MacTTSFilePlayer(MacTTSPlayer):
self._wait_for_termination(tag) self._wait_for_termination(tag)
def _on_done(self, ret: Future, cb: OnDoneCallback) -> None: def _on_done(self, ret: Future, cb: OnDoneCallback) -> None:
try:
ret.result() ret.result()
except PlayerInterrupted:
# don't fire done callback when interrupted
return
# inject file into the top of the audio queue # inject file into the top of the audio queue
from aqt.sound import av_player from aqt.sound import av_player