I want the option 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
I read that the callback functions are gone for the newer versions of VLC so i downgreded to 2.0.5 version.
i have problems here:
vlc.var.set(input, "spu", trackNumber)
and i get this error:
lua warning: Error while running script C:\Program Files (x86)\VideoLAN\VLC\lua\extensions\toggle_subtitles.lua, function (null)(): ...86)\VideoLAN\VLC\lua\extensions\toggle_subtitles.lua:32: bad argument #-1 to 'set' (boolean expected, got number)
i can confirm that the trackNumber is 1, 2 or 3.
Here is the current code:
Code: Select all
-- "toggle_subtitles_dialog.lua" -- VLC Extension
function activate()
create_dialog()
end
function deactivate()
end
function create_dialog()
dlg = vlc.dialog("Toggle Subtitles")
-- Button for Български (Bulgarian) with hotkey B
dlg:add_button("Български (B)", function() toggle_subtitle(1) end, 1, 1, 1, 1)
-- Button for English with hotkey E
dlg:add_button("English (E)", function() toggle_subtitle(2) end, 2, 1, 1, 1)
-- Button for Românesc (Romanian) with hotkey R
dlg:add_button("Românesc (R)", function() toggle_subtitle(3) end, 3, 1, 1, 1)
end
function toggle_subtitle(trackNumber)
vlc.msg.info(trackNumber)
-- Check if the track number is valid
if trackNumber and type(trackNumber) == "number" then
-- Set the subtitle track using vlc.var.set
local input = vlc.object.input()
vlc.var.set(input, "spu", trackNumber)
else
-- Print an error message if the track number is invalid
vlc.msg.err("Invalid track number: "..tostring(trackNumber))
end
end
function descriptor()
return {
title = "Subtitles Switcher",
version = "1.0",
author = "Nikolay Boyadzhiev",
url = "https://example.com",
description = "Dialog box to toggle between subtitle tracks",
capabilities = {}
}
end