forked from zc62/mpv-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoloop.lua
More file actions
33 lines (28 loc) · 897 Bytes
/
autoloop.lua
File metadata and controls
33 lines (28 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- mpv issue 5222
-- Automatically set loop-file=inf for duration < given length. Default is 5s
-- Use script-opts=autoloop-duration=x in mpv.conf to set your preferred length
local autoloop_duration = 5
function getOption()
local opt = mp.get_opt("autoloop-duration")
if (opt ~= nil) then
local test = tonumber(opt)
if (test ~= nil) then
autoloop_duration = test
end
end
end
getOption()
local was_loop = mp.get_property_native("loop-file")
function set_loop()
local duration = mp.get_property_native("duration")
if duration ~= nil then
if duration < autoloop_duration + 0.001 then
mp.command("set loop-file inf")
else
mp.set_property_native("loop-file", was_loop)
end
else
mp.set_property_native("loop-file", was_loop)
end
end
mp.register_event("file-loaded", set_loop)