我不知道为什么,但有时
Exoplayer
缓冲我的视频非常慢。我的服务器响应正常,互联网也很快,但有时 Exoplayer
会缓慢缓冲我的视频不到 1 秒。而且播放时每 1-2 秒就会缓冲一次。
int MIN_BUFFER_DURATION = 3000;
int MAX_BUFFER_DURATION = 8000;
int MIN_PLAYBACK_RESUME_BUFFER = 1500;
int MIN_PLAYBACK_START_BUFFER = 500;
LoadControl loadControl = new DefaultLoadControl.Builder()
.setAllocator(new DefaultAllocator(true, 16))
.setBufferDurationsMs(MIN_BUFFER_DURATION,
MAX_BUFFER_DURATION,
MIN_PLAYBACK_START_BUFFER,
MIN_PLAYBACK_RESUME_BUFFER)
.setTargetBufferBytes(-1)
.setPrioritizeTimeOverSizeThresholds(true).createDefaultLoadControl();
TrackSelector trackSelector = new DefaultTrackSelector();
simpleExoPlayer = new ExoPlayer.Builder(this).setTrackSelector(trackSelector).setLoadControl(loadControl).build();
binding.exoPlayerView.setPlayer(simpleExoPlayer);
mediaItem = MediaItem.fromUri(getVid);
simpleExoPlayer.addMediaItem(mediaItem);
simpleExoPlayer.prepare();
simpleExoPlayer.play();
我正在我的 Exoplayer 和
Chrome Browser player.
Chrome 浏览器player plays my video 4X faster than my app
Exoplayer` 中测试我的视频?我在同一时间播放同一个视频。有人也在 exoplayer git 中问了这个问题,但没有得到好的答案或结果,请参阅他们的问题 exoplayer 问题 github 这同样的问题导致了我!
有谁知道为什么会发生这种情况?你的回答会对我有帮助。
确保您使用的是最新版本的 Exoplayer。截至撰写本文时,即为 2.10.4。
尝试增加 LoadControl 中的缓冲区持续时间值:
int MIN_BUFFER_DURATION = 3000; // 3 seconds
int MAX_BUFFER_DURATION = 8000; // 8 seconds
int MIN_PLAYBACK_RESUME_BUFFER = 1500; // 1.5 seconds
int MIN_PLAYBACK_START_BUFFER = 500; // 0.5 seconds
LoadControl loadControl = new DefaultLoadControl.Builder()
.setAllocator(new DefaultAllocator(true, 16))
.setBufferDurationsMs(
MIN_BUFFER_DURATION,
MAX_BUFFER_DURATION,
MIN_PLAYBACK_START_BUFFER,
MIN_PLAYBACK_RESUME_BUFFER)
.setTargetBufferBytes(-1)
.setPrioritizeTimeOverSizeThresholds(true)
.createDefaultLoadControl()
int TARGET_BUFFER_BYTES = (int) (0.25 * videoBitrate); // 25% of the video bitrate in bytes
LoadControl loadControl = new DefaultLoadControl(
new DefaultAllocator(true, 16),
TARGET_BUFFER_BYTES,
DEFAULT_MIN_REBUFFER_MS,
DEFAULT_MAX_LOADING_MS,
DEFAULT_MIN_ELAPSED_MS_BEFORE_STOPPING,
false
);
int allocatorSize = 2 * 1024 * 1024; // 2MB
Allocator allocator = new DefaultAllocator(true, allocatorSize);
LoadControl loadControl = new DefaultLoadControl(
allocator,
DEFAULT_TARGET_BUFFER_BYTES,
DEFAULT_MIN_REBUFFER_MS,
DEFAULT_MAX_LOADING_MS,
DEFAULT_MIN_ELAPSED_MS_BEFORE_STOPPING,
false
);
将以下设置为 0 -> 测试行为 -> 根据需要进行调整
int MIN_PLAYBACK_RESUME_BUFFER = 1500;
int MIN_PLAYBACK_START_BUFFER = 500;
对我有用的是:
int MIN_BUFFER_DURATION = 3000; // 3 seconds
int MAX_BUFFER_DURATION = 3000; // 3 seconds
int MIN_PLAYBACK_RESUME_BUFFER = 1500; // 1.5 seconds
int MIN_PLAYBACK_START_BUFFER = 500; // 0.5 seconds
LoadControl loadControl = new DefaultLoadControl.Builder() .setAllocator(new DefaultAllocator(true, 16)) .setBufferDurationsMs(MIN_BUFFER_DURATION, MAX_BUFFER_DURATION, MIN_PLAYBACK_START_BUFFER, MIN_PLAYBACK_RESUME_BUFFER) .setTargetBufferBytes(-1) .setPrioritizeTimeOverSizeThresholds(true).createDefaultLoadControl();
ExoPlayer player= new ExoPlayer.Builder(this).setLoadControl(loadControl).build();
根据 @Carter McKay 的回答,刚刚更改了 MAX_BUFFER_DURATION。