如何在Exo Player 2中添加多个字幕 [英] how to add multiple subtitles in Exo Player 2

查看:445
本文介绍了如何在Exo Player 2中添加多个字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用ExoPlayer 2显示字幕.用户可以选择语言(英语,德语或阿拉伯语).视频链接是HLS(.m3u8),字幕是.str文件.

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.

有样品吗?

推荐答案

链接(我在您的原始帖子中添加了评论)将是您如何围绕文本轨道选择构建用户界面.然后,要实际获取要添加到mp4文件(或任何格式)的曲目,您需要使用MergingMediaSource.简单的版本看起来像这样:

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.

我从此博客文章-但我相信ExoPlayer文档中也包含相同的代码.该代码块与我在其他答案中链接的示例代码结合在一起此处应该足以让您获得一些字幕.

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.

这篇关于如何在Exo Player 2中添加多个字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆