Skip to content

Commit 57f9799

Browse files
committed
osc.lua: show the first selected audio track id with --lavfi-complex
Similar to current-tracks, when the selected audio track is combined with another one or with an ffmpeg filter, show the first selected track id instead of "-". This was requested by a user on IRC. Also avoid fetching aid and sid on each render.
1 parent 05154e1 commit 57f9799

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

player/lua/osc.lua

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ local state = {
308308
hide_timer = nil,
309309
cache_state = nil,
310310
idle = false,
311+
current_tracks = {},
311312
audio_track_count = 0,
312313
sub_track_count = 0,
313-
no_video = false,
314314
file_loaded = false,
315315
enabled = true,
316316
input_enabled = true,
@@ -704,15 +704,21 @@ end
704704
local function update_tracklist(_, track_list)
705705
state.audio_track_count = 0
706706
state.sub_track_count = 0
707-
state.no_video = true
707+
state.current_tracks = {}
708708

709709
for _, track in pairs(track_list) do
710+
if track.selected and not state.current_tracks[track.type] then
711+
state.current_tracks[track.type] = track.id
712+
end
713+
710714
if track.type == "audio" then
711715
state.audio_track_count = state.audio_track_count + 1
712716
elseif track.type == "sub" then
713717
state.sub_track_count = state.sub_track_count + 1
714-
elseif track.type == "video" and track.selected then
715-
state.no_video = false
718+
719+
if track.selected and track["main-selection"] == 0 then
720+
state.current_tracks.sub = track.id
721+
end
716722
end
717723
end
718724

@@ -2364,7 +2370,7 @@ local function osc_init()
23642370
if user_opts.tracknumberswidth == 0 then
23652371
return icons.audio
23662372
end
2367-
local track = mp.get_property_number("aid", "-")
2373+
local track = state.current_tracks.audio or "-"
23682374
local count = state.audio_track_count
23692375
return icons.audio .. label_style .. " " ..
23702376
(user_opts.layout == "floating" and to_fraction(track, count)
@@ -2380,7 +2386,7 @@ local function osc_init()
23802386
if user_opts.tracknumberswidth == 0 then
23812387
return icons.subtitle
23822388
end
2383-
local track = mp.get_property_number("sid", "-")
2389+
local track = state.current_tracks.sub or "-"
23842390
local count = state.sub_track_count
23852391
return icons.subtitle .. label_style .. " " ..
23862392
(user_opts.layout == "floating" and to_fraction(track, count)
@@ -3028,7 +3034,7 @@ tick = function()
30283034
elseif state.fullscreen and user_opts.showfullscreen
30293035
or (not state.fullscreen and user_opts.showwindowed) then
30303036

3031-
if state.no_video and state.file_loaded and user_opts.audioonlyscreen then
3037+
if not state.current_tracks.video and state.file_loaded and user_opts.audioonlyscreen then
30323038
render_logo()
30333039
else
30343040
render_wipe(state.logo_osd)
@@ -3169,7 +3175,7 @@ end)
31693175

31703176
mp.register_event("file-loaded", function()
31713177
state.file_loaded = true
3172-
state.no_video = mp.get_property_native("current-tracks/video") == nil
3178+
state.current_tracks.video = mp.get_property_native("current-tracks/video/id")
31733179
request_tick()
31743180
end)
31753181
mp.add_hook("on_unload", 50, function()

0 commit comments

Comments
 (0)