1. Are you ready for the Galaxy S20? Here is everything we know so far!

subtitle not showing in exoplayer 2.7.3

Discussion in 'Android Development' started by ora jackson, Nov 11, 2020.

  1. ora jackson

    ora jackson Lurker
    Thread Starter

    i use exoplayer to play mkv video from external url. the video is horriblesub and i try to add my own subtitle (.vtt) but the subtitle does not showing. only original sub from the video is showing..how can i switch the original subtitle in video with my own subtitle ? if i play mkv video with no original sub, my own sub is showing..but if i play video with original sub, my own sub cant showing. this is my code

    public void setSelectedSubtitle(MediaSource mediaSource, String subtitle, Context context) {
    MergingMediaSource mergedSource;
    if (subtitle != null) {
    Uri subtitleUri = Uri.parse(subtitle);

    Format subtitleFormat = Format.createTextSampleFormat(
    null, // An identifier for the track. May be null.
    MimeTypes.TEXT_VTT, // The mime type. Must be set correctly.
    Format.NO_VALUE, // Selection flags for the track.
    "en"); // The subtitle language. May be null.

    DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context,
    Util.getUserAgent(context, CLASS_NAME), new DefaultBandwidthMeter());


    MediaSource subtitleSource = new SingleSampleMediaSource
    .Factory(dataSourceFactory)
    .createMediaSource(subtitleUri, subtitleFormat, C.TIME_UNSET);

    mergedSource = new MergingMediaSource(mediaSource, subtitleSource);
    player.prepare(mergedSource, false, false);
    player.setPlayWhenReady(true);
    //resumePlayer();

    } else {
    Toast.makeText(context, "there is no subtitle", Toast.LENGTH_SHORT).show();
    }
     



    1. Download the Forums for Android™ app!


      Download

       
  2. mikedt

    mikedt 你好

    ".vtt" subtitles? Never heard of that one before. All subtitle files I've encountered are either suffixed .srt or .ass.

    I don't know this "exoplayer", but media players I've used, like VLC, Kodi, etc, can open subtitle file no problems when playing MKV etc. movies.

    Also what's that code about? Bearing in mind I'm not a developer, so really can't help you with code.
     
  3. Milo Willamson

    Milo Willamson Android Expert

    I cannot help you with coding either, still try embeling them and disabling them first. I kind of forgot how to turn mine on my Moto edge, but with automatic ones on my Adult Swim app, I do not bother with them either as much.
     
    mikedt likes this.
Loading...

Share This Page

Loading...