MPVMediaControl
MPVMediaControl copied to clipboard
How to make MPVMediaControl.exe process to close together with mpv?
After closing mpv, the process continues to run in the taskbar indefinitely, and this behavior is especially annoying because it makes previously opened files unable to be moved/deleted as Windows claims they are currently running.
Yeah this is the reason I stick with the now abandoned MPV-SMTC. It opens and closes with MPV, it's also a silent subprocess so it never needs to be in the task bar to begin with.
Yeah this is the reason I stick with the now abandoned MPV-SMTC. It opens and closes with MPV, it's also a silent subprocess so it never needs to be in the task bar to begin with.
It doesn't seem to work on Windows 11 :(
Also interested in this for the same reason. Constantly getting "cannot delete folder in use" errors from Windows while deleting and re-organizing videos because this was still open in the System Tray even though all instances of mpv were closed.
Looks like the ExitIfNoControllers() in notify_media.lua gets registered to run when mpv is closed. It does an IPC send that's received in PipeServer.cs. Considering the other IPC calls seem to be working correctly, I assume it's getting to this case successfully.
Not at all familiar with C# or relevant Windows APIs but the Exit() function that's supposed to be called eventually is also used here in Program.cs for the tray icon's context menu, which works as you'd expect. Therefore, I also assume the Exit() function itself is also working correctly, if called.
The above mentioned setQuit case:
- Checks if the
"quit"parameter istrue(should be, based on the IPC call innotify_media.lua). - Checks that
Program.AppContext,controller, andcontroller.File.Patharen't null (seems like that should be true but idk?). - Sets the controller to stop if it isn't already (probably fine?).
- Calls
RemoveController(pid)(no idea if it's successfully doing so). - Calls
ExitIfNoControllers()which should then do some async stuff to callExit(), but only if_controllers.Count == 0, which should be true if the previous step worked.
So maybe:
- Registering with mpv to run a lua function on shutdown isn't working?
- IPC send/receive failure?
- One of those variables is null?
RemoveController(pid)isn't successfully doing so... maybe thepidisn't matching the one used when theMediaControllerwas created?- Something with the
asyncorawaitinExitIfNoControllers()that callsExit()? Seems correct to my untrained eye.
Wish I was set up and qualified to help, proooobably not a difficult problem to debug (knock on wood).
A quick fix for this without support for multiple mpv instances:
function on_quit()
if shot_path then
os.remove(shot_path)
end
write_to_socket("^[setQuit](pid=" .. pid .. ")(quit=true)(socket_name=" .. mpv_socket_name .. ")$")
-- Force kill MPVMediaControl.exe
mp.command_native({
name = "subprocess",
playback_only = false,
args = {"taskkill", "/F", "/IM", "MPVMediaControl.exe"},
})
end