gpt4 book ai didi

java - 视频持续时间设置不正确 (exoplayer2)

转载 作者:行者123 更新时间:2023-12-02 04:52:03 26 4
gpt4 key购买 nike

使用exopler2,我可以毫无问题地播放带字幕的视频,但搜索栏不显示任何内容,并且不显示视频时长如果我删除字幕代码并仅设置视频源,一切正常,但我需要添加副标题这是我的代码

注意:我使用 m3u8 视频和 srt 作为字幕

enter image description here

    //  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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com