function auto_loop() local max = 20 local file_duration = mp.get_property_number("duration", 0) print(file_duration) -- Images have a duration of 0, so don’t loop and use -- image-display-duration instead if file_duration == 0 then mp.set_property("loop-file", "no") -- If a GIF or video have duration shorter than seconds -- make it loop for at least seconds elseif file_duration < max then mp.set_property("loop-file", math.floor(max / file_duration)) -- For longer file, play it only once else mp.set_property("loop-file", "no") end print(mp.get_property("loop-file")) end mp.register_event("file-loaded", auto_loop)