'Sometime video buffering very slowly in exoplayer?

I don't know why, but sometimes Exoplayer buffers my video very slowly. My server is responding properly and the internet is also fast but sometimes Exoplayer buffers my video slowly for less than 1 second. And it buffering always after every 1-2 seconds on playing.

        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();

I'm testing my video in my Exoplayer and Chrome Browser player. Chrome browserplayer plays my video 4X faster than my appExoplayer`? And I'm playing the same video and the same time. Someone also asked this question in exoplayer git but not got a good answer or result see their question exoplayer issue github this same issue causing me!

Does anyone know why this happens? Your answer will helpful for me.



Solution 1:[1]

set the following to 0 -> test behavior -> make adjustments if needed

int MIN_PLAYBACK_RESUME_BUFFER = 1500;
int MIN_PLAYBACK_START_BUFFER = 500;

Solution 2:[2]

  1. Make sure you are using the latest version of Exoplayer. As of this writing, that is 2.10.4.

  2. Try increasing the buffer duration values in your 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()
  1. Try using a different LoadControl. For example, you could use DefaultLoadControl with a smaller target buffer (e.g. 25% of the video bitrate):
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); 
  1. Try using a different Allocator. For example, you could use a larger one:
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); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 orimen
Solution 2