Skip to content

Instantly share code, notes, and snippets.

@nilninull
Last active November 27, 2022 12:07
Show Gist options
  • Save nilninull/64389dcbe7e43bed8df6c9aef914d58e to your computer and use it in GitHub Desktop.
Save nilninull/64389dcbe7e43bed8df6c9aef914d58e to your computer and use it in GitHub Desktop.
Function to restart mpv by pressing the key.
-- When using the version under development, the image sometimes
-- freezes during seek. Restarting mpv cures it, but it is
-- troublesome, so I wrote a script to solve the problem.
local function restart_mpv()
mp.command("quit-watch-later")
local cmds = {"run", "mpv"}
-- local opts = mp.get_property_native("property-list")
local opts = mp.get_property_native("options")
mp.set_property("msg-level", "all=no")
for _, o in ipairs(opts) do
if (mp.get_property_bool("option-info/" .. o .. "/set-from-commandline")) then
table.insert(cmds, "--" .. o .. "=" .. mp.get_property(o))
end
end
local plist = mp.get_property_native("playlist")
for _, o in ipairs(plist) do
table.insert(cmds, o.filename)
end
-- mp.command_native(cmds)
mp.command_native_async(cmds)
end
mp.add_key_binding("Alt+ENTER", "restart_mpv_0", restart_mpv)
mp.add_key_binding("Alt+MOUSE_BTN2", "restart_mpv_1", restart_mpv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment