gpt4 book ai didi

android - 如何在 Exo Player 2 中添加多个字幕

转载 作者:行者123 更新时间:2023-11-30 00:19:49 28 4
gpt4 key购买 nike

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

我找不到任何示例来执行此操作。

有 sample 吗?

最佳答案

link我作为评论添加到您的原始帖子将是您将如何围绕文本轨道选择构建 UI。然后要真正将轨道添加到您的 mp4 文件(或任何格式),您需要使用 MergingMediaSource。简单版本如下所示:

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

您可以将多个字幕轨道合并到视频源中。许多不同的文件格式都被接受。

我从 this blog post 得到了那个特定的代码示例- 但我相信相同的代码也在 ExoPlayer 文档中。该代码块结合了我在其他答案中链接到的示例代码 here应该足以让您获得一些字幕。

请告诉我这是否适合您。

关于android - 如何在 Exo Player 2 中添加多个字幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46521570/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com