summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2021-06-20 15:45:43 +0300
committeravih <avih@users.noreply.github.com>2021-06-22 18:12:29 +0300
commit76b1ac57a4f49ff2c7f18b7e46aefa7fb3362984 (patch)
treec3ff55c6b795c231ab9b51a0164d09c566aeaa08
parenta17d79907a256456393f395a939762ed757b4240 (diff)
downloadmpv-76b1ac57a4f49ff2c7f18b7e46aefa7fb3362984.tar.bz2
mpv-76b1ac57a4f49ff2c7f18b7e46aefa7fb3362984.tar.xz
osc: seekbar hover/drag: display target chapter at the title
Fixes #8925
-rw-r--r--DOCS/man/osc.rst3
-rw-r--r--player/lua/osc.lua34
2 files changed, 35 insertions, 2 deletions
diff --git a/DOCS/man/osc.rst b/DOCS/man/osc.rst
index 236a3dd3cb..9dd09f3241 100644
--- a/DOCS/man/osc.rst
+++ b/DOCS/man/osc.rst
@@ -43,7 +43,8 @@ pl next
============= ================================================
title
- | Displays current media-title, filename, or custom title
+ | Displays current media-title, filename, custom title, or target chapter
+ name while hovering the seekbar.
============= ================================================
left-click show playlist position and length and full title
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