gpt4 book ai didi

java - Android - ExoPlayer 在没有太多缓冲的情况下尽快开始播放

转载 作者:行者123 更新时间:2023-12-05 01:02:25 28 4
gpt4 key购买 nike

我正在使用一个简单的 exoplayer 测试代码从 URL 播放视频,我注意到播放器连接后,它会缓冲大约 2-3 秒,直到它开始播放(我指的是大约 2-3 秒,因为我不确切知道它是如何在内部工作的,它可能是一定数量的字节)。考虑到连接需要大约 1-2 秒(然后开始缓冲,然后有效地开始视频),开始视频需要大约 4 秒,这似乎太多了。我使用速度测试应用程序在检测到的速度约为 24Mbits/s 的连接上测试了 3 秒视频、640x480、1.23MB 大小)。

有没有办法加快视频的启动速度(例如,通过设置启动所需的初始缓冲大小)?

这是我的测试代码:

TrackSelector trackSelector = new DefaultTrackSelector();
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);

PlayerView playerView = findViewById(R.id.player_view);
playerView.setPlayer(player);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "simpleAudioApp"));
dataSourceFactory = new CacheDataSourceFactory(getSimpleCacheInstance(),
dataSourceFactory);

Uri audioSourceUri = Uri.parse("http://...somevideo.mp4");
MediaSource audioSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(audioSourceUri);
LoopingMediaSource loopingSource = new LoopingMediaSource(audioSource, 1);

// Prepare the player with the source.
player.prepare(loopingSource);
player.setPlayWhenReady(true);
player.addListener(new Player.EventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == Player.STATE_ENDED) {
Toast.makeText(TestActivity2.this, "Video ended", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(TestActivity2.this, "video state chnged: " + playbackState, Toast.LENGTH_LONG).show();
}
}

@Override
public void onRepeatModeChanged(int repeatMode) {
Toast.makeText(TestActivity2.this, "repeat chnged: " + repeatMode, Toast.LENGTH_LONG).show();
}
});

有没有办法做到这一点?

最佳答案

您可以将自定义负载控制与此模式一起使用:

DefaultLoadControl loadControl = new DefaultLoadControl
.Builder()
.setBufferDurationsMs(minBufferMS, maxBufferMs, bufferForPlayackMS, bufferForPlaybackAfterRebufferMs)
.createDefaultLoadControl();
示例用法:
TrackSelector trackSelector = new DefaultTrackSelector();

DefaultLoadControl loadControl = new DefaultLoadControl
.Builder()
.setBufferDurationsMs(32*1024, 64*1024, 1024, 1024)
.createDefaultLoadControl();
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

关于java - Android - ExoPlayer 在没有太多缓冲的情况下尽快开始播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54073206/

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