Bind subtitles to a button

Microsoft Windows specific usage questions
Forum rules
Please post only Windows specific questions in this forum category. If you don't know where to post, please read the different forums' rules. Thanks.
Valchek
New Cone
New Cone
Posts: 5
Joined: 08 Mar 2024 13:47

Bind subtitles to a button

Postby Valchek » 08 Mar 2024 13:58

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.

Lotesdelere
Cone Master
Cone Master
Posts: 10008
Joined: 08 Sep 2006 04:39
Location: Europe

Re: Bind subtitles to a button

Postby Lotesdelere » 08 Mar 2024 16:25

Default hotkeys settings are:
v -> cycle subtitles tracks
Alt+v -> cycle subtitles tracks in reverse order

Valchek
New Cone
New Cone
Posts: 5
Joined: 08 Mar 2024 13:47

Re: Bind subtitles to a button

Postby Valchek » 09 Mar 2024 09:07

Yes i know the default settings. I am looking for a way to bind specific button to specific subtitle language.

Valchek
New Cone
New Cone
Posts: 5
Joined: 08 Mar 2024 13:47

Re: Bind subtitles to a button

Postby Valchek » 13 Mar 2024 09:23

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)


Return to “VLC media player for Windows Troubleshooting”

Who is online

Users browsing this forum: No registered users and 97 guests