summaryrefslogtreecommitdiffstats
path: root/TOOLS/lua/test-hooks.lua
blob: 4e84d9e46561a61b00060aecbcc71aef0355a717 (plain)
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
local utils = require("mp.utils")

function hardsleep()
    os.execute("sleep 1s")
end

local hooks = {"on_before_start_file", "on_load", "on_load_fail",
               "on_preloaded", "on_unload", "on_after_end_file"}

for _, name in ipairs(hooks) do
    mp.add_hook(name, 0, function()
        print("--- hook: " .. name)
        hardsleep()
        print("    ... continue")
    end)
end

local events = {"start-file", "end-file", "file-loaded", "seek",
                "playback-restart", "idle", "shutdown"}
for _, name in ipairs(events) do
    mp.register_event(name, function()
        print("--- event: " .. name)
    end)
end

local props = {"path", "metadata"}
for _, name in ipairs(props) do
    mp.observe_property(name, "native", function(name, val)
        print("property '" .. name .. "' changed to '" ..
              utils.to_string(val) .. "'")
    end)
end