I am using Exoplayer for streaming URL. I want to add srt file in exoplayer. But I think player not support srt file so I put my file content in 1 variable.
How to show subtitles in android exoplayer?
A bit late but it might help others using Exoplayer 1.5.1 where DebugTrackRenderer has been removed.
Use,
DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
SingleSampleSource textSampleSource = new SingleSampleSource(subTitleUrl, textDataSource,
MediaFormat.createTextFormat(MediaFormat.NO_VALUE,MimeTypes.APPLICATION_SUBRIP, MediaFormat.NO_VALUE, TrackRenderer.MATCH_LONGEST_US, null));
TrackRenderer textRenderer = new TextTrackRenderer(textSampleSource, player,
player.getMainHandler().getLooper());
Above code passes subTitleUrl to SingleSampleSource.
Then just enable your TextTrackRenderer that is enabled by default as,
player.setSelectedTrack(YourPlayer.TYPE_TEXT, YourPlayer.TRACK_DEFAULT);
It will do the trick.
I got the solution. I convert srt file into TTML file using
TimedTextFileFormat
Below is my code to convert srt to TTML,After that in player activity pass subtitle to respected builder, In this i am sending to HlsRendererBuilder.
From HlsRendererBuilder class pass it to TrackRenderer, // Build the debug renderer.
And in DebugTrackRenderer class in run method use below code,