我使用ExoPlayer来播放来自URL的音频。我有XML格式的字幕,如下所示:
[
{
"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忍者请帮我)
发布于 2021-04-17 15:15:28
如果字幕XML来自HTTP:
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);发布于 2017-11-12 04:51:44
您可以将json格式转换为.str格式,并将其保存为文件。现在,ExoPlayer可以显示.str文件。下面是str格式的示例:
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. https://stackoverflow.com/questions/42241213
复制相似问题