使用exopler2,我可以毫无问题地播放带字幕的视频,但搜索栏不显示任何内容,并且不显示视频时长 如果我删除字幕代码并仅设置视频源,一切正常,但我需要添加副标题 这是我的代码
注意:我使用 m3u8 视频和 srt 作为字幕
// Create the player
player = ExoPlayerFactory.
newSimpleInstance(this, trackSelector, loadControl);
// Bind the player to the view.
//simpleExoPlayerView.setPlayer(player);
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new
DefaultDataSourceFactory(this,
Util.getUserAgent(this,
"exoplayer2example"), bandwidthMeter);
//FOR LIVESTREAM LINK:
// MediaSource videoSource =new HlsMediaSource(videoUri,dataSourceFactory,1,null,null);
MediaSource videoSource = new
HlsMediaSource.Factory(dataSourceFactory).
createMediaSource(videoUri);
player.prepare(videoSource);
//time = player.getDuration();
// Log.d("TTTTTTT", String.valueOf(player.getDuration()));
//Build the subtitle MediaSource.
Format textFormat = Format.createTextSampleFormat(null,
MimeTypes.APPLICATION_SUBRIP,
null, Format.NO_VALUE, Format.NO_VALUE,
"ar", null, Format.NO_VALUE);
MediaSource subtitleSource = new SingleSampleMediaSource.Factory(
dataSourceFactory).createMediaSource(subtitleUri,
textFormat, C.TIME_UNSET);
//merging the video with subTitle
MergingMediaSource mergedSource = new MergingMediaSource(subtitleSource, videoSource);
//prepare video with sub title
player.prepare(mergedSource);
//set the player to view
simpleExoPlayerView.setPlayer(player);
//auto play
player.setPlayWhenReady(true);
最佳答案
创建 MergingMediaSource 时 MediaSource 顺序出现问题
MergingMediaSource mergedSource = new MergingMediaSource(subtitleSource, videoSource);
应该是这样的
MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource);
关于java - 视频持续时间设置不正确 (exoplayer2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56430306/