• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps subtitle not showing in exoplayer 2.7.3

ora jackson

Lurker
Nov 11, 2020
1
0
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();
}
 
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();
}

".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.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones