有时视频在 exoplayer 中缓冲非常慢?

MDE*_*DEV 9 java android exoplayer exoplayer2.x

我不知道为什么,但有时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();
Run Code Online (Sandbox Code Playgroud)

我正在我的 Exoplayer 和Chrome Browser player. Chrome 浏览器player plays my video 4X faster than my appExoplayer` 中测试我的视频?我在同一时间播放同一个视频。有人也在 exoplayer git 中问了这个问题,但没有得到好的答案或结果,请参阅他们的问题exoplayer 问题 github这同样的问题引起了我!

有谁知道为什么会发生这种情况?你的回答会对我有帮助。

Car*_*Kay 4

  1. 确保您使用的是最新版本的 Exoplayer。截至撰写本文时,该版本为 2.10.4。

  2. 尝试增加 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()
Run Code Online (Sandbox Code Playgroud)
  1. 尝试使用不同的 LoadControl。例如,您可以将 DefaultLoadControl 与较小的目标缓冲区一起使用(例如视频比特率的 25%):
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
); 
Run Code Online (Sandbox Code Playgroud)
  1. 尝试使用不同的分配器。例如,您可以使用更大的:
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
); 
Run Code Online (Sandbox Code Playgroud)