本文介绍了如何在Exoplayer android中向视频添加字幕(.SRT文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在一个项目中,我应该在Android中播放.srt文件以及视频.我正在研究Exoplayer的示例,但是无法播放带视频的.srt文件.
i am working on a project where i should play .srt files along with video in android. I was working through the samples of Exoplayer but cant able to play .srt files with video.
我使用的代码是
MediaSource mediaSource = new HlsMediaSource(Uri.parse("https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8"),
mediaDataSourceFactory, mainHandler, null);
Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP,
null, Format.NO_VALUE, Format.NO_VALUE, "en", null);
Uri uri = Uri.parse("http://www.storiesinflight.com/js_videosub/jellies.srt");
MediaSource subtitleSource = new SingleSampleMediaSource(uri, mediaDataSourceFactory, textFormat, C.TIME_UNSET);
// Plays the video with the sideloaded subtitle.
MergingMediaSource mergedSource =
new MergingMediaSource(mediaSource, subtitleSource);
player.prepare(mergedSource);
任何人都可以向我建议此解决方案或与此相同的任何教程链接.非常感谢您的帮助!
Can anyone please suggest me solution for this or any tutorial links for the same. Your help is very much appreciated !
推荐答案
SubtitleView subtitleView=(SubtitleView)findViewById(com.google.android.exoplayer2.R.id.exo_subtitles);
player.setTextOutput(new ComponentListener());
public class ComponentListener implements TextRenderer.Output{
@Override
public void onCues(List<Cue> cues) {
if (subtitleView != null) {
subtitleView.onCues(cues);
}
}
}
显示/隐藏字幕视图:
subtitleView.setVisiblity(Visible/Gone);
这篇关于如何在Exoplayer android中向视频添加字幕(.SRT文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!