Skip to content

Instantly share code, notes, and snippets.

@blackarcher21
Last active May 29, 2026 23:54
Show Gist options
  • Select an option

  • Save blackarcher21/162dc1bef708e90082c6c4f9500c1997 to your computer and use it in GitHub Desktop.

Select an option

Save blackarcher21/162dc1bef708e90082c6c4f9500c1997 to your computer and use it in GitHub Desktop.
mpv script - remember audio volume
local filepath = mp.command_native({"expand-path", "~~/volume"})
local loadfile = io.open(filepath, "r")
if loadfile then
set_volume = string.sub(loadfile:read(), 8)
loadfile:close()
mp.set_property_number("volume", set_volume)
end
mp.register_event("shutdown",
function()
local savefile = io.open(filepath, "w+")
savefile:write("volume=" .. mp.get_property("volume"), "\n")
savefile:close()
end
)
@sephid86

sephid86 commented Aug 23, 2023

Copy link
Copy Markdown
  1. local filepath = mp.command_native({"expand-path", "~~/volume"})

The above line works fine for mpv on Linux,
but It doesn't work well with mpv on Windows.

In order to work normally on both Windows and Linux, you need to modify it as follows.

  1. local filepath = mp.command_native({"expand-path", "~/.mpv_volume"})

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