Subtitle Support in ExoPlayer v2.0
Hello, Can any one share the code/steps necessary to support subtitle in the exoplayer 2.0
I know there is a sample code in one of the issues that is cosed, but that is working with v1 release.
I think the classes have been moved, So if any one can provide with the sample code(with all parameters) that would be highly helpful.
There are so many different variants of what it means to "support subtitles". You need to be more specific with exactly what media + subtitles you're trying to play (ideally providing links to sample content).
Hello @ojw28 Thanks for the quick reply, My need is straight forward, I would like to dispaly sub titles in the formatt of .srt, I would give a link to the sub title file ( can be online or offline) and the text must be displayed on the player.
I have tried the SingleSampleMediaSource method that was there in the exoplayer guide but except subtitle url no other params were specified, can you please explain those params and how to use MergingMediaSource Method to achieve the required objective.
Hello @ojw28 any news on my issue
Hello is there any update on this issue
Here's a basic example for playing subtitles from a Uri srtUri alongside some other mediaSource providing video/audio:
Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP,
null, Format.NO_VALUE, Format.NO_VALUE, "en", null);
MediaSource textMediaSource = new SingleSampleMediaSource(srtUri, mediaDataSourceFactory,
textFormat, C.TIME_UNSET);
MediaSource mediaSourceWithText = new MergingMediaSource(mediaSource, textMediaSource);
I've hardcoded the language to "en", but this is only used for signaling information on available tracks to your app. See the demo app source to find out how mediaDataSourceFactory is constructed.
Renderer:2 [ D/EventLogger: Group:0, adaptive_supported=N/A [ D/EventLogger: [X] Track:0, id=null, mimeType=text/vtt, language=en, supported=YES ] ]
Hello @andrewlewis I am getting this in the logcat but no subtitles are being shown on the screen, am I doing some thing wrong, like need to add some kind of subtitle view to the screen.
I thought the media will play as it is interleaved into the video, if this is not the case can you suggest the other way.
I have tried with this url : https://www.iandevlin.com/html5test/webvtt/upc-video-subtitles-en.vtt
for vtt formatt and
this for srt format;
storage/storage0/test.srt, if doing any thing wrong please tell me.
SimpleExoPlayerView already has a SubtitleView, so if you're using that (without any customization) it should just work once you provide the right source to the player. If not, consider switching to using SimpleExoPlayerView, or read its source to see how the TextRenderer is hooked up to the SubtitleView and replicate it in your app.
I was able to play the WebVTT URL successfully using the code above but changing the MIME type from MimeTypes.APPLICATION_SUBRIP to MimeTypes.TEXT_VTT.