【发布时间】:2019-06-03 15:21:48
【问题描述】:
使用 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);
【问题讨论】:
标签: java android exoplayer2.x