Installing sometimes stalls/fails because of mpv.exe still running... very big and often an exact duplicate

This is a longstanding issue, and others have reported it, for example here and also here.

Occasionally (maybe one in ten times?) when installing a new version of Anki, the installation fails because of mpv.exe being undeletable (because the program is running).

Error opening file for writing:

...\AppData\Local\Programs\Anki\mpv.exe

Click Retry to try again, or Cancel to stop the installation.

Retry doesn’t work because the error just pops up again.

The existing mpv.exe is in use for some reason and cannot be deleted. The solution I use is simply to rename it before doing the Retry, and then eventually delete it when it becomes possible to do so (usually after the next reboot). Or it could be terminated through the Task Manager. But unsophisticated users will probably just give up.

Anki itself is not running because I shut it down before attempting the installation.

A few things to note:

  • Is there some programmatic way to ensure that the bundled copy of mpv.exe always terminates when Anki terminates? Like sending a kill signal to the process ids of child processes.
  • I’m not sure why mpv.exe is even running when using Anki for text-based decks. Instead of having it automatically launched when Anki starts, would it make sense to have it start up on-demand the first time the user plays an audio file?
  • When using the renaming trick mentioned above to allow the new copy of mpv.exe to get installed alongside the old one, it invariably turns out to be byte-for-byte identical to the existing copy. This is actually a big file at about 72 MB! It’s more than twice the size of anki.exe, and almost exactly half the size of anki-23.12-windows.qt6.exe. So half the global bandwidth of all user downloads could be saved if there was some smart way to avoid a redundant download of an identical copy of the existing mpv.exe, which serves no purpose (and occasionally breaks the install process).

Maybe unbundle mpv.exe from the Anki downloads and allow Anki to be used without it. If the user attempts to use some functionality that requires mpv, a popup could direct them to download it. When the installer runs (or when Anki runs), it checks for the presence of an existing mpv.exe file and does a SHA-256 check on it to make sure it’s the right version.

Okay, maybe the above was over-complicated. But the main thing would be:

mpv should be automatically stopped when a profile or Anki is closed. It can’t ensure this if Anki closes due to a crash, however.

Okay then.

As a suggestion for eventual future directions, instead of using mpv as a separate process, there’s a libmpv C API, and C is callable from Rust. The website says that using libmpv “is generally recommended when mpv is used as playback backend for a completely different application.” It might be a more robust approach.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.