Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpv not opening file in same process #3811

Open
nmoorthy524 opened this issue Nov 17, 2016 · 24 comments
Open

mpv not opening file in same process #3811

nmoorthy524 opened this issue Nov 17, 2016 · 24 comments

Comments

@nmoorthy524
Copy link

nmoorthy524 commented Nov 17, 2016

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?

@ghost
Copy link

ghost commented Nov 18, 2016

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.)

@phling1009
Copy link

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

@garoto
Copy link
Contributor

garoto commented Nov 24, 2016

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

@phling1009
Copy link

Thanks

@Skibicki
Copy link

Skibicki commented Apr 7, 2017

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
Copy link

Skibicki commented Apr 7, 2017

Another script
It runs properly from powershell.

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

@Jj0YzL5nvJ
Copy link

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

@Hrxn
Copy link
Contributor

Hrxn commented Apr 9, 2017

ping 127.0.0.1 -n 2 >nul

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

@SilverEzhik
Copy link

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.

@agyild
Copy link

agyild commented Jul 21, 2019

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?

@Akemi
Copy link
Member

Akemi commented Jul 21, 2019

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.

@agyild
Copy link

agyild commented Jul 21, 2019

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.

@Akemi
Copy link
Member

Akemi commented Jul 21, 2019

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.

@OpenA
Copy link

OpenA commented Feb 13, 2020

os:win

sry

@frgmnt
Copy link

frgmnt commented Jun 29, 2020

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

@garoto
Copy link
Contributor

garoto commented Jun 29, 2020

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
Copy link
Contributor

garoto commented Jun 29, 2020

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

@Jj0YzL5nvJ
Copy link

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?

@garoto
Copy link
Contributor

garoto commented Jul 1, 2020

@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.

@Max-Enrik
Copy link

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

@SilverEzhik
Copy link

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

@ge9
Copy link

ge9 commented Jan 17, 2023

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)

@ReneTC
Copy link

ReneTC commented May 23, 2024

anyone knows how to enable this UMPV feature in linux?

@guidocella
Copy link
Contributor

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests