In the VLC media player, it is possible to disable subtitles. It is unclear how to do that programmatically using VLCJ.
I have searched the Internet for information on how to do this, and could not find any information based on the current version of VLCJ. I did find some information, but the solutions shown are using API calls that apparently no longer exist in the current API.
How does one enable or disable subtitles in an application using the current vlcj? Can someone either provide the appropriate API call or (if the process is complex) point me to an example (using the current version of the API) of how to do so?
Advertisement
Answer
With contemporary version of vlcj (4.7.x):
mediaPlayer().subpictures().setTrack(subtitleTrackId);
Note the Javadoc on that method, you can not (reliably) just use track id 0, 1, 2, …, you need to use the trackDescriptions
method:
List<TrackDescription> tracks = mediaPlayer().subpictures().trackDescriptions();
Iterate the track descriptions to find the track you want, and then get the id and pass it to the setTrack
method described above.
To disable subtitles, pass the id of the track that has the “Disable” description.
https://javadoc.io/doc/uk.co.caprica/vlcj/latest/uk/co/caprica/vlcj/player/base/SubpictureApi.html
The API will change with vlcj 5.x and VLC 4.x when they are eventually released (the underlying native API dealing with track selection changed).