ora jackson
Lurker
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();
}
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();
}