pass task manager in instead of creating a new one

This commit is contained in:
Damien Elmes 2020-01-21 06:49:09 +10:00
parent 0b5e22253b
commit 1beae4f858
3 changed files with 11 additions and 7 deletions

View File

@ -395,7 +395,7 @@ close the profile or restart Anki."""
##########################################################################
def setupSound(self) -> None:
aqt.sound.setup_audio(self.pm.base)
aqt.sound.setup_audio(self.taskman, self.pm.base)
# Collection load/unload
##########################################################################

View File

@ -157,11 +157,13 @@ class SimpleProcessPlayer(SoundOrVideoPlayer):
"A player that invokes a new process for each file to play."
_on_done: Optional[OnDoneCallback]
_taskman = TaskManager()
_terminate_flag = False
args: List[str] = []
env: Optional[Dict[str, str]] = None
def __init__(self, taskman: TaskManager):
self._taskman = taskman
def play(self, tag: AVTag, on_done: OnDoneCallback) -> None:
stag = cast(SoundOrVideoTag, tag)
self._terminate_flag = False
@ -198,7 +200,8 @@ class SimpleMpvPlayer(SimpleProcessPlayer):
]
)
def __init__(self, base_folder: str) -> None:
def __init__(self, taskman: TaskManager, base_folder: str) -> None:
super().__init__(taskman)
conf_path = os.path.join(base_folder, "mpv.conf")
self.args += ["--no-config", "--include=" + conf_path]
@ -654,7 +657,7 @@ for (k, v) in _exports:
##########################################################################
def setup_audio(base_folder: str) -> None:
def setup_audio(taskman: TaskManager, base_folder: str) -> None:
# legacy global var
global mpvManager
@ -671,7 +674,7 @@ def setup_audio(base_folder: str) -> None:
atexit.register(cleanupMPV)
else:
# fall back on mplayer
mplayer = SimpleMplayerPlayer()
mplayer = SimpleMplayerPlayer(taskman)
av_player.players.append(mplayer)
# currently unused
@ -682,4 +685,4 @@ def setup_audio(base_folder: str) -> None:
if isMac:
from aqt.tts import MacTTSPlayer
av_player.players.append(MacTTSPlayer())
av_player.players.append(MacTTSPlayer(taskman))

View File

@ -17,7 +17,8 @@ class TTSPlayer(Player): # pylint: disable=abstract-method
class MacTTSPlayer(TTSPlayer):
_taskman = TaskManager()
def __init__(self, taskman: TaskManager):
self._taskman = taskman
def play(self, tag: AVTag, on_done: Callable[[], None]) -> None:
ttag = cast(TTSTag, tag)