diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2021-06-20 15:45:43 +0300 |
---|---|---|
committer | avih <avih@users.noreply.github.com> | 2021-06-22 18:12:29 +0300 |
commit | 76b1ac57a4f49ff2c7f18b7e46aefa7fb3362984 (patch) | |
tree | c3ff55c6b795c231ab9b51a0164d09c566aeaa08 /player/lua/osc.lua | |
parent | a17d79907a256456393f395a939762ed757b4240 (diff) | |
download | mpv-76b1ac57a4f49ff2c7f18b7e46aefa7fb3362984.tar.bz2 mpv-76b1ac57a4f49ff2c7f18b7e46aefa7fb3362984.tar.xz |
osc: seekbar hover/drag: display target chapter at the title
Fixes #8925
Diffstat (limited to 'player/lua/osc.lua')
-rw-r--r-- | player/lua/osc.lua | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 8701f4acd0..e3cefd1642 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -593,8 +593,38 @@ end -- Element Rendering -- +-- returns nil or a chapter element from the native property chapter-list +function get_chapter(possec) + local cl = mp.get_property_native("chapter-list", {}) + local ch = nil + + -- chapters might not be sorted by time. find nearest-before/at possec + for n=1, #cl do + if possec >= cl[n].time and (not ch or cl[n].time > ch.time) then + ch = cl[n] + end + end + return ch +end + function render_elements(master_ass) + -- when the slider is dragged or hovered and we have a target chapter name + -- then we use it instead of the normal title. we calculate it before the + -- render iterations because the title may be rendered before the slider. + state.forced_title = nil + local se, ae = state.slider_element, elements[state.active_element] + if se and (ae == se or (not ae and mouse_hit(se))) then + local dur = mp.get_property_number("duration", 0) + if dur > 0 then + local possec = get_slider_value(se) * dur / 100 -- of mouse pos + local ch = get_chapter(possec) + if ch and ch.title and ch.title ~= "" then + state.forced_title = "Chapter: " .. ch.title + end + end + end + for n=1, #elements do local element = elements[n] @@ -1741,7 +1771,8 @@ function osc_init() ne = new_element("title", "button") ne.content = function () - local title = mp.command_native({"expand-text", user_opts.title}) + local title = state.forced_title or + mp.command_native({"expand-text", user_opts.title}) -- escape ASS, and strip newlines and trailing slashes title = title:gsub("\\n", " "):gsub("\\$", ""):gsub("{","\\{") return not (title == "") and title or "mpv" @@ -1918,6 +1949,7 @@ function osc_init() ne = new_element("seekbar", "slider") ne.enabled = not (mp.get_property("percent-pos") == nil) + state.slider_element = ne.enabled and ne or nil -- used for forced_title ne.slider.markerF = function () local duration = mp.get_property_number("duration", nil) if not (duration == nil) then |