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

View file

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