Page 1 of 1

Bind subtitles to a button

Posted: 08 Mar 2024 13:58
by Valchek
Hello,

We are building a museum. We will have some videos for the visitors. I want the option for every visitor to be able to choose the language of the subtitles. I am looking for an option to play a video file and have let's say 3 tracks of subtitles in different languages. I want to achieve switching between the tracks(not cycle with V) like this:
Press E - the sub-track is in English
Press B - the sub-track is in Bulgarian
Press V - the sub-track is in Romanian

Of course, the buttons can be different, but I am looking for this functionality. Is there a way to achieve that? Extension? Rewrite parts of the source code(i have good c# understanding, but I am not sure if I am up to the task to code on c)?
I am using the latest version of VLC 3.0.20, but I am willing to roll back an older version if it is needed.
If this cannot be done with vlc is there any other player that supports that?

Thanks in advance.

Re: Bind subtitles to a button

Posted: 08 Mar 2024 16:25
by Lotesdelere
Default hotkeys settings are:
v -> cycle subtitles tracks
Alt+v -> cycle subtitles tracks in reverse order

Re: Bind subtitles to a button

Posted: 09 Mar 2024 09:07
by Valchek
Yes i know the default settings. I am looking for a way to bind specific button to specific subtitle language.

Re: Bind subtitles to a button

Posted: 13 Mar 2024 09:23
by Valchek
Hello again, I am not sure if i can post code here, but I will try in the hopes I wont get a ban.
I tried to make an addon(with the help of chatGPT). VLC see the extension and recognize it, but It wont work and nothing is happening on key press. Any ideas here?
The script is saved in : ~\AppData\Roaming\vlc\lua\extensions
Here is the code:
-- Save this script as "toggle_subtitles.lua"

-- Define key mappings for subtitle tracks
local subtitleMappings = {
["1"] = 1, -- Press '1' for Bulgarian
["2"] = 2, -- Press '2' for English
["3"] = 3 -- Press '3' for Romanian
}

-- Function to toggle between subtitle tracks
function toggleSubtitle(trackNumber)
vlc.var.set(vlc.object.input(), "spu", trackNumber)
end

-- Function to handle key events
function onKeyPress(event)
local key = event.get_chars()
local trackNumber = subtitleMappings[key]

if trackNumber then
toggleSubtitle(trackNumber)
end
end

-- Register the key event handler
vlc.msg.info("Subtitle toggling script loaded. Press '1', '2', or '3' to switch subtitles.")
vlc.var.add_callback(vlc.object.libvlc(), "key-press", onKeyPress)