Can I use something like vlc.var.add_callback(vlc.object.input(), "time", pause, VAR)
Input's time doesn't work, but you can do this:
Code: Select all
--Global setting for minimum seconds between callbacks.
--desired_interval = 5.00
function activate()
input_callback("add")
end
function deactivate()
input_callback("delete")
end
function input_changed()
input_callback("add")
--Probably safe to redundantly add, and a nil input is handled in the func.
end
function input_callback(action)
assert(action == "add" or action == "delete")
local input = vlc.object.input()
if input and action == "add" then
vlc.var.add_callback(input, "intf-event", my_callback, "Hello world!")
elseif input and action == "delete" then
vlc.var.del_callback(input, "intf-event", my_callback, "Hello world!")
end
--"intf-event" triggers about 5x/second.
end
last_call = 0
function my_callback(var_name, old_value, new_value, user_data)
--Ordinarily one would do this to only act every N seconds.
--if os.clock() - last_call < desired_interval then return end
last_call = os.clock()
--Do something periodically
end
VAR is any custom info you want, in case you use a single callback for multiple events and need to differentiate them, or something.
When you deactivate, you'll have to give the exact same args to del_callback(), so it's convenient to manage add and delete in the same place.
This isn't granular enough for 0.04s accuracy however. But since os.clock has subsecond accuracy, track the average elapsed time between callbacks, and when ({math.modf(vlc.input.time)})[2] is nearer to 0.96 than your average callback gap, do a CPU-abusing while loop until the moment arrives (or abort if it passes by).