how to add multiple subtitles in Exo Player 2

a 夏天 提交于 2019-12-11 10:58:00

问题


I want to show subtitles with ExoPlayer 2 . users can choose between languages (English,German, or Arabic) . Video links are HLS (.m3u8) and subtitles are .str files .

I couldn't find any samples to do this.

is there any sample?


回答1:


The link I added as a comment to your original post will be how you'll build the UI around text track selection. Then to actually get the tracks to be added to your mp4 file (or whatever the format is), you'll want to use a MergingMediaSource. The simple version looks like so:

MediaSource videoSource = new ExtractorMediaSource(videoUri, ...);
MediaSource subtitleSource = new SingleSampleMediaSource(subtitleUri, ...);
// Plays the video with the sideloaded subtitle.
MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource);

You can merge multiple subtitle tracks into the video source. Many different file formats are accepted.

I got that particular code sample from this blog post - but I believe that same code is also in the ExoPlayer documentation. That code block combined with the sample code that I link to in my other answer here should be enough to get you some subtitles.

Please let me know if that works for you.



来源:https://stackoverflow.com/questions/46521570/how-to-add-multiple-subtitles-in-exo-player-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!