mpv icon indicating copy to clipboard operation
mpv copied to clipboard

mpv not opening file in same process

Open nmoorthy524 opened this issue 9 years ago • 24 comments

I am on the latest windows 64 bit build available here: https://mpv.srsfckn.biz/ (10/20 as of today). I already have mpv as the default filetype. When I have mpv already open and I click on a video to play in my file explorer, instead of playing in the already open mpv process, it creates a new one so now there's 2 mpvs playing. Is this as intended and if so, how do I make it stick to using only 1 process?

nmoorthy524 avatar Nov 17 '16 23:11 nmoorthy524

It's a feature. On Linux there's a script (umpv) to get one-process behavior, but not on Windows. (Though you could attempt to write such a script for Windows.)

ghost avatar Nov 18 '16 11:11 ghost

I need this feature,It could open many file at the same time? how could I switch on this function?

phling1009 avatar Nov 24 '16 07:11 phling1009

As a possible workaround, there's rossy's mpv-open-file-dialog Lua script.

garoto avatar Nov 24 '16 15:11 garoto

Thanks

phling1009 avatar Nov 25 '16 11:11 phling1009

I found 2 things, but I'm not sure how to use them. Notify me if you know. This uses a program and registry entry. zenden2k/context-menu-launcher and the other is Powershell Code

$process = "mspaint"
$ret = Get-Process -Name $process -ErrorAction SilentlyContinue 
if ($ret) {
	Write-Host "INFO: $process already running, skipping start of another instance of the same process"
} else {
	Write-Host "VERBOSE: Starting $process now"
	Invoke-Item "$process.exe"	
}

@rossy @yangyzp

Skibicki avatar Apr 07 '17 07:04 Skibicki

Another script It runs properly from powershell.

if (-Not (Get-Process "mpv" -ErrorAction SilentlyContinue | Where-Object {-not $_.HasExited }))
{
  & "C:\mpv\mpv.exe"
}

Skibicki avatar Apr 07 '17 09:04 Skibicki

With all due respect, using PowerShell to do just that is stupid damn, it's like wanting to kill flies to cannon shots. Not to mention that PowerShell is just another "permanent security hole" in the operating system.

This batch do exact the same:

@echo off
tasklist | find /i "mpv.exe"
if errorlevel 1 start "" mpv.exe %*

A more hostile variant:

@echo off
taskkill /im "mpv.exe" /f
start "" mpv.exe %*

Less hostile...:

@echo off
taskkill /im "mpv.exe"
ping 127.0.0.1 -n 2 >nul
start "" mpv.exe %*

cya

Jj0YzL5nvJ avatar Apr 08 '17 12:04 Jj0YzL5nvJ

ping 127.0.0.1 -n 2 >nul

Just to avoid any possible confusion: This is just the old wait trick..

Hrxn avatar Apr 09 '17 12:04 Hrxn

I posted this on another issue already, but this one appears to be specifically about Windows.

Anyway, I gave implementing single instance mode for Windows a shot: https://github.com/SilverEzhik/umpvw

It handles things macOS-style - opening a file will replace what you have running`. It also handles opening multiple files as a playlist via IPC.

SilverEzhik avatar Mar 22 '18 01:03 SilverEzhik

I don't understand why dev team does not implement this mechanism by creating a simple named kernel object (e.g. semaphore) at startup and check if the particular object exists at startup and if so redirect playback request to existing instance and terminate the extra instance. This is usually how it is handled instead of unnecessary 3rd party scripts. Can somebody explain?

agyild avatar Jul 21 '19 20:07 agyild

i don't know who that "dev team" team is. though that person probably doesn't want to implement it since they doesn't see a need for it.

Akemi avatar Jul 21 '19 22:07 Akemi

i don't know who that "dev team" team is. though that person probably doesn't want to implement it since they doesn't see a need for it.

Here's a need for it: You are already playing a file in the background, meanwhile you are also exploring other files, finally you decide to choose a new file to play and click on it. Now you have two instances playing different files simultaneously causing you to manually have to close the other instance, which could have been solved with the method i have talked about. This is not a obscure niche feature, it is already implemented in various software (e.g. MPC-HC, VLC etc.).

I am aware of the open source nature of the project and I know that there is not a "dev team" per se. But usually in every project there is a team of people actively working on the project, that's what I meant.

agyild avatar Jul 21 '19 22:07 agyild

that's just the use case and no one questioned that one.

i meant a personal need, so that person is not implementing it. if the interests of that specific dev doesn't align with the interest of specific users it can't be helped. there is even less of an incentive since it is already possible with scripts etc and if one doesn't aim for a specific implementations this issue is basically 'solved'.

you either have to wait till someone implements your wanted feature or you have to do it yourself.

Akemi avatar Jul 21 '19 22:07 Akemi

os:win

sry

OpenA avatar Feb 13 '20 18:02 OpenA

I'm new to using mpv and I've been trying to figure out how to deal with this on Windows. I've already installed using shinchiro's build from mpv's site. Should I be using @SilverEzhik 's method to fix it. If so, how would I go about that if I already have the latest build installed?

If I should be creating a batch file, how should I be handling it(how to make it run when I want to, and how to make it stop when it shouldn't be running)? @Jj0YzL5nvJ

frgmnt avatar Jun 29 '20 16:06 frgmnt

Should I be using @SilverEzhik 's method to fix it. If so, how would I go about that if I already have the latest build installed?

Most likely yes, just follow the instructions found at his other repo here.

garoto avatar Jun 29 '20 19:06 garoto

Alternatively, I also made the following batch file a long time ago to test single-instance mode via the built-in Windows cmd.exe facility, so I'll just paste it below in case someone finds it useful:

@echo off
setlocal enableextensions enabledelayedexpansion

:: strip double quotes from the "%1" argument if present, just in case (it'll be added later)
set "input=%~1"
:: convert backslashes into forward slashes, so 'echo loadfile' doesn't need escaped backslashes
set "output=%input:\=/%"
	set cli_args=%*
	set mpv_args=!cli_args:%1=!

tasklist /FI "IMAGENAME eq mpv.exe" 2>nul | findstr /i "mpv.exe" >nul
	IF %errorlevel% EQU 0 ( goto :mpvIsRunning ) ELSE (
		start "" mpv.exe --input-ipc-server=mpv-socket %mpv_args% "%output%"
		goto :End
	)

:mpvIsRunning
	echo loadfile "%output%">\\.\pipe\mpv-socket

:End
endlocal

garoto avatar Jun 29 '20 19:06 garoto

I'm new to using mpv and I've been trying to figure out how to deal with this on Windows. I've already installed using shinchiro's build from mpv's site. Should I be using @SilverEzhik 's method to fix it. If so, how would I go about that if I already have the latest build installed?

If I should be creating a batch file, how should I be handling it(how to make it run when I want to, and how to make it stop when it shouldn't be running)? @Jj0YzL5nvJ

@shinchiro, how about an alternative installer using @garoto's script?

Jj0YzL5nvJ avatar Jul 01 '20 10:07 Jj0YzL5nvJ

@shinchiro, how about an alternative installer using @garoto's script?

Please don't. This is just a silly prototype, if even that, and while it seems to work as far I was able to test it, I can only imagine it can|will fail in many specific circunstances. Also, associating this .bat in the registry for video extensions, will make a cmd.exe window to pop-up briefly everytime a video is launched from any GUI application, and that's not very pretty.

garoto avatar Jul 01 '20 20:07 garoto

--started-from-file --playlist-enqueue works for VLC. I think there'd be a command line for mpv to solve this issue?

Max-Enrik avatar Oct 11 '20 22:10 Max-Enrik

For anybody still dealing with this on Windows 10, I packaged mpv for the Microsoft Store with a single instance mode wrapper and file association defaults: https://www.microsoft.com/store/productId/9P3JFR0CLLL6

The source is available here: https://github.com/SilverEzhik/mpv-msix

SilverEzhik avatar Sep 04 '21 06:09 SilverEzhik

Hi, I implemented a more versatile version of above mentioned zenden2k/context-menu-launcher.

https://github.com/ge9/ExecuteCommand-Pipe

It can pass input files to any program through standard input (in UTF-8). No change of order during interprocess communication, and no limitation on path length or number of files. I confirmed it works perfectly with mpv. (It has no function of appending files to the queue in existing mpv window)

ge9 avatar Jan 17 '23 14:01 ge9

anyone knows how to enable this UMPV feature in linux?

ReneTC avatar May 23 '24 10:05 ReneTC

https://raw.githubusercontent.com/mpv-player/mpv/master/TOOLS/umpv

On Arch you can get it from /usr/share/mpv/scripts/umpv.

guidocella avatar May 23 '24 10:05 guidocella

You can use https://github.com/mpv-player/mpv/blob/master/TOOLS/umpv wrapper script on Windows too now. Patches welcome if that not enough for you, native in mpv ipc would be possible too, but wrapper script achieves the same effect.

kasper93 avatar Feb 05 '25 19:02 kasper93