Add support to use only one instance of mpv
Maybe I'm just lacking of reading comprehension, but I can't see a way to achieve this on the man page. Is it possible to make an option to use the same mpv instance to play files? Instead of having to close one first and then open another one.
I know you can achieve this with an input file and loadfile PATH but...
On what operating system? On OSX, there's a way (you have to use the bundle functionality).
For other platforms: No, there's no such feature yet. I can't say I like the idea. Implementing this would probably require lots of weird extra code (checking a named pipe on startup? something like this) for a feature I usually hate. I would accept a patch though. (As long as it doesn't use dbus.)
Well, I hope someone who actually knows programming can implement this. I was talking about Linux, sorry didn't say it.
On Linux you can use "pidof" or a similar program (pgrep, probably others) to simply check if there is a mpv process. If pidof succeeds you know that mpv is already running.
You can launch mpv with a bash script like this to check if there is already a mpv process.
#! /bin/bash
if pidof mpv
then echo "mpv already running"
else mpv $1
fi
It will print a message ("mpv already running") if there is already a mpv process. If there in no mpv process it will start mpv and pass the first argument called to the script to mpv. If you want to pass more than one argument to mpv you can quote them all together like this when you call the script.
one_mpv "--ao=alsa file_name.mkv"
You can make it more complicated by replacing the message with something else like killing the already running mpv process (or closing it cleanly by sending keyboard commands with xdotool) and then starting another mpv process.
I made a small Python script that implements something like this: https://github.com/mpv-player/mpv/blob/master/TOOLS/umpv
There are some caveats, so read the comments at the start of the script.
Tell me if you tried it and whether you like it.
Well, there's that script, and since there's no (further) interest, I'll just close this.
Feel free to comment or reopen, though.
Wow what? I am so surprised this is not implemented? How??
Because the main developer of this software thinks the concept is excruciatingly stupid.
It clearly isn't @wm4 , in fact this would be the expected behavior of a video player. Why not even allow it as a configuration for people who don't think it's excruciatingly stupid?
It clearly isn't @wm4 , in fact this would be the expected behavior of a video player. Why not even allow it as a configuration for people who don't think it's excruciatingly stupid?
I'm assuming you didn't read the thread and find the script that @wm4 went to the trouble of authoring, testing and publishing for this exact use case? Does that not cover your use case?
(FWIW I also think this sort of "detect other running instances and send commands to them" is extremely unexpected and stupid, borderline nonsensical behavior for a command line program. At best I could be convinced to only enable it in pseudo-gui mode)
Even for GUI programs, this kind of behavior is inconvenient and annoying. Why the hell would you not start a new program when I ask for a new program?
Single Instance
mpv/scripts/single_instance.lua
- Windows:
local mp = require 'mp'
local utils = require 'mp.utils'
function close_other_instances()
local current_pid = utils.getpid()
local process_list = utils.subprocess({
args = { "tasklist", "/FI", "IMAGENAME eq mpv.exe" },
cancellable = false
})
if process_list.status == 0 then
for line in process_list.stdout:gmatch("[^\r\n]+") do
local pid = line:match("mpv%.exe%s+%d+")
if pid then
pid = tonumber(pid:match("%d+"))
if pid and pid ~= current_pid then
utils.subprocess({
args = { "taskkill", "/PID", tostring(pid), "/F" },
cancellable = false
})
end
end
end
end
end
mp.register_event("start-file", close_other_instances)
- Linux:
local mp = require 'mp'
local utils = require 'mp.utils'
function close_other_instances()
local current_pid = utils.getpid()
local process_list = utils.subprocess({
args = { "pgrep", "-x", "mpv" },
cancellable = false
})
if process_list.status == 0 then
for pid in process_list.stdout:gmatch("%d+") do
pid = tonumber(pid)
if pid and pid ~= current_pid then
utils.subprocess({
args = { "kill", tostring(pid) },
cancellable = false
})
end
end
end
end
mp.register_event("start-file", close_other_instances)
Even for GUI programs, this kind of behavior is inconvenient and annoying. Why the hell would you not start a new program when I ask for a new program?
Because many programmers are stupified by the obvious.
Because the main developer of this software thinks the concept is excruciatingly stupid.
WOW... is it that same ass clown who made VLC? That dude is PURE TRASH. People begged that fuktard to allow VLC to simply open up the next file in a directory FOR YEARS ans the maggot refused to impliment it.
Single Instance
mpv/scripts/single_instance.luaI'm going to have to try this because Mpv.Net [which allows 1 instance] has a couple annoying broken features as well. Thanks.
WOW... is it that same ass clown who made VLC? That dude is PURE TRASH. People begged that fuktard to allow VLC to simply open up the next file in a directory FOR YEARS ans the maggot refused to impliment it.
If you pay me a billion dollars I'll implement this feature in mpv and VLC.
WOW... is it that same ass clown who made VLC? That dude is PURE TRASH. People begged that fuktard to allow VLC to simply open up the next file in a directory FOR YEARS ans the maggot refused to impliment it.
If you pay me a billion dollars I'll implement this feature in mpv and VLC.
LOL, yo couldn't pay me a billion to ever touch that POS player [shit LC] again..