4

I want to add subtitles in vlc video player by using the SRT format file.

I used LibVlc in android.

  1. add libVLC in GRADLE file

    implementation 'org.videolan.android:libvlc-all:3.3.13'

  2. MoviesDetailsActivity.java

Here is my code to add subtitles. (MovieDetailsActivity.java)

private void initVideoPlayer() {
 
    ArrayList<String> args = new ArrayList<>();
    String subtitleUrl = "https://example.com/subtitles/60ccb930346f3.srt"; /* this would be example url, not real */

    args.add("--file-caching=2000");
    args.add("-vvv");
    LibVLC mLibVlc = new LibVLC(MovieDetailsActivity.this, args);
    MediaPlayer mMediaPlayer = new MediaPlayer(mLibVlc);
    mMediaPlayer = new MediaPlayer(mLibVlc);
    mMediaPlayer.setEventListener(this);
    mMediaPlayer.attachViews(videoLayout, null, true, true);

    Uri subtitle = Uri.parse(url.toString());
    mMediaPlayer.addSlave(IMedia.Slave.Type.Subtitle, subtitle, true);  /* add subtitles here with URL */

    URL url = new URL(movie_url);  // this is movie url
    Uri movie = Uri.parse(url.toString());
    Media media = new Media(mLibVlc, movie); // media source for video
    media.setHWDecoderEnabled(true, false); 
    media.addOption(":network-caching=150");
    media.addOption(":clock-jitter=0");
    media.addOption(":clock-synchro=0");
    media.addOption(":-v");
    mMediaPlayer.setMedia(media);  // set media 
    media.release();

    mMediaPlayer.play();
}

I did like this. But I can't see subtitles. only playing video with audio. In the EXOPlayer it works well, But in the VLC player, I couldn't. What is the solution?

Saikrishna Rajaraman
  • 3,205
  • 2
  • 16
  • 29

0 Answers0