Skip to content

Commit 0b2c08b

Browse files
guidocellakasper93
authored andcommitted
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 76df24f commit 0b2c08b

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

player/lua/osc.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ local state = {
310310
idle_active = false,
311311
audio_track_count = 0,
312312
sub_track_count = 0,
313-
track_position = {},
313+
current_tracks = {},
314314
no_video = false,
315315
file_loaded = false,
316316
enabled = true,
@@ -712,16 +712,22 @@ end
712712
local function update_tracklist(_, track_list)
713713
state.audio_track_count = 0
714714
state.sub_track_count = 0
715-
state.track_position = {}
715+
state.current_tracks = {}
716716
state.no_video = true
717717

718718
for _, track in ipairs(track_list) do
719719
if track.type == "audio" then
720720
state.audio_track_count = state.audio_track_count + 1
721-
state.track_position[track.id .. "audio"] = state.audio_track_count
721+
722+
if track.selected and not state.current_tracks["audio"] then
723+
state.current_tracks["audio"] = state.audio_track_count
724+
end
722725
elseif track.type == "sub" then
723726
state.sub_track_count = state.sub_track_count + 1
724-
state.track_position[track.id .. "sub"] = state.sub_track_count
727+
728+
if track["main-selection"] == 0 then
729+
state.current_tracks["sub"] = state.sub_track_count
730+
end
725731
elseif track.type == "video" and track.selected then
726732
state.no_video = false
727733
end
@@ -2438,8 +2444,7 @@ local function osc_init()
24382444
if user_opts.tracknumberswidth == 0 then
24392445
return icons.audio
24402446
end
2441-
local tid = mp.get_property_number("aid", 0)
2442-
local track = state.track_position[tid .. "audio"] or "-"
2447+
local track = state.current_tracks.audio or "-"
24432448
local count = state.audio_track_count
24442449
return icons.audio .. label_style .. " " ..
24452450
(user_opts.layout == "floating" and to_fraction(track, count)
@@ -2455,8 +2460,7 @@ local function osc_init()
24552460
if user_opts.tracknumberswidth == 0 then
24562461
return icons.subtitle
24572462
end
2458-
local tid = mp.get_property_number("sid", 0)
2459-
local track = state.track_position[tid .. "sub"] or "-"
2463+
local track = state.current_tracks.sub or "-"
24602464
local count = state.sub_track_count
24612465
return icons.subtitle .. label_style .. " " ..
24622466
(user_opts.layout == "floating" and to_fraction(track, count)

0 commit comments

Comments
 (0)