相关疑难解决方法(0)

如何在Exoplayer android中向视频添加字幕(.SRT文件)?

我正在一个项目中,我应该在Android中播放.srt文件以及视频。我正在研究Exoplayer的示例,但是无法播放带视频的.srt文件。

我使用的代码是

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);
Run Code Online (Sandbox Code Playgroud)

任何人都可以为我提出解决方案或与此相同的任何教程链接。非常感激你的帮助 !

java android android-mediaplayer exoplayer

7
推荐指数
1
解决办法
5103
查看次数

标签 统计

android ×1

android-mediaplayer ×1

exoplayer ×1

java ×1