clock.lua 863 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. local opts = {
  2. time_format = "%_H:%M:%S",
  3. ass_position = "7",
  4. show_clock_binding = "Alt+c",
  5. toggle_clock_binding = "Alt+C"
  6. }(require "mp.options").read_options(opts, "clock")
  7. local clock = mp.create_osd_overlay("ass-events")
  8. local function update_clock()
  9. local time = os.date(opts.time_format)
  10. clock.data="{osd-ass-cc/1}{\\a" .. opts.ass_position .. " }" .. time
  11. clock:update()
  12. end
  13. local timer = mp.add_periodic_timer(0.1, update_clock)
  14. timer:stop()
  15. local function toggle_clock()
  16. if timer:is_enabled() then
  17. timer:stop()
  18. clock:remove()
  19. else
  20. timer:resume()
  21. end
  22. end
  23. local function remove_clock()
  24. clock:remove()
  25. end
  26. local function show_clock()
  27. update_clock()
  28. mp.add_timeout(2, remove_clock)
  29. end
  30. mp.add_key_binding(opts.show_clock_binding, "ShowClock", show_clock)
  31. mp.add_key_binding(opts.toggle_clock_binding, "ToggleClock", toggle_clock)