javaandroidexoplayerexoplayer2.x

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