首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExoPlayer:显示字幕

ExoPlayer:显示字幕
EN

Stack Overflow用户
提问于 2017-02-15 05:15:55
回答 2查看 983关注 0票数 0

我使用ExoPlayer来播放来自URL的音频。我有XML格式的字幕,如下所示:

代码语言:javascript
复制
    [
    {
        "id": 1,
        "startTime": "00:00:00",
        "endTime": "00:00:05",
        "textEn": "towns, in late 15th-century England.",
        "textRu": null
    },
    {
        "id": 2,
        "startTime": "00:00:05",
        "endTime": "00:00:10",
        "textEn": "the first thing to note is that in stark contrast to today, England was an overwhelmingly rural country.",
        "textRu": null
    }
]

我知道在使用ExoPlayer播放时有一种显示字幕的方法。但是,我扫描了开发人员指南中的所有内容:ExoPlayer开发人员指南,但没有找到如何做到这一点,因为文档非常糟糕。另外,是否XML格式的字幕适合于ExoPlayer,如果现在,我应该如何转换它们和格式。ExoPlayer忍者请帮我)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-04-17 15:15:28

如果字幕XML来自HTTP:

代码语言:javascript
复制
Format subtitleFormat = Format.createTextSampleFormat(
                null, // An identifier for the track. May be null.
                MimeTypes.APPLICATION_SUBRIP, // The mime type. Must be set correctly.
                C.SELECTION_FLAG_DEFAULT, // Selection flags for the track.
                null); // The subtitle language. May be null.

MediaSource subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory)
                        .createMediaSource(Uri.parse(subtitleUrl), subtitleFormat, C.TIME_UNSET);

        MergingMediaSource mergedSource =
                new MergingMediaSource(videoSource, subtitleSource);
player.prepare(mergedSource);
票数 1
EN

Stack Overflow用户

发布于 2017-11-12 04:51:44

您可以将json格式转换为.str格式,并将其保存为文件。现在,ExoPlayer可以显示.str文件。下面是str格式的示例:

代码语言:javascript
复制
1
00:02:17,440 --> 00:02:20,375
Senator, we're making
our final approach into Coruscant.

2
00:02:20,476 --> 00:02:22,501
Very good, Lieutenant. 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42241213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档