Fix two mpv issues on Windows (#2294)

* Fix mpv with two Windows accounts at the same time

Closes #2203

* Add a workaround for audio cut off early on Windows

Closes #1730
This commit is contained in:
kelciour 2023-01-03 04:59:39 +03:00 committed by GitHub
parent 2270ff425a
commit e9428449ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -92,6 +92,9 @@ class MPVBase:
"--gapless-audio=no",
]
if is_win:
default_argv += ["--af-add=lavfi=[apad=pad_dur=0.150]"]
def __init__(self, window_id=None, debug=False):
self.window_id = window_id
self.debug = debug
@ -143,7 +146,7 @@ class MPVBase:
--input-unix-socket option.
"""
if is_win:
self._sock_filename = "ankimpv"
self._sock_filename = "ankimpv{}".format(os.getpid())
return
fd, self._sock_filename = tempfile.mkstemp(prefix="mpv.")
os.close(fd)
@ -156,12 +159,11 @@ class MPVBase:
start = time.time()
while self.is_running() and time.time() < start + 10:
time.sleep(0.1)
if is_win:
# named pipe
try:
self._sock = win32file.CreateFile(
r"\\.\pipe\ankimpv",
r"\\.\pipe\{}".format(self._sock_filename),
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
0,
None,