mirror of
https://github.com/mpv-player/mpv
synced 2025-02-03 05:31:34 +00:00
osc: seekbar hover/drag: display target chapter at the title
Fixes #8925
This commit is contained in:
parent
a17d79907a
commit
76b1ac57a4
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user