Sometime video buffering very slowly in exoplayer?
Asked Answered
M

3

9

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.

Maiga answered 9/5, 2022 at 9:34 Comment(12)
Update .setTargetBufferBytes(C.LENGTH_UNSET)Encore
@PrasadTamgale sir please explain what you wrote. I don't understand?Maiga
I was saying, maybe try setting the target buffer bytes size to C.LENGTH_UNSET & see if that helps.Encore
@PrasadTamgale can you explain to me how to implement this? with some code?Maiga
Same code of yours, just update from .setTargetBufferBytes(-1) to .setTargetBufferBytes(C.LENGTH_UNSET)Encore
@PrasadTamgale does not work! The problem is the same.Maiga
@PrasadTamgale any other solution??Maiga
I don't see anything wrong but the set values for the parameters might be causing the scenario which you are mentioning.Encore
Let's do few tweaks and check? Make DefaultAllocator(true,1024) & also .setTargetBufferBytes(1024)Encore
@PrasadTamgale let me explain. This problem is happening on 30-second video and size is ~6MB and this problem is not happening on 30-second video and size is ~3MB. and this problem happens ~8 times on 10 times play. Do you know why this problem is happening?Maiga
int MIN_PLAYBACK_RESUME_BUFFER = 1500; int MIN_PLAYBACK_START_BUFFER = 500; this is the problem @MDev. They together become 2000 which is 2 seconds. I increased the values and then, the buffer happens for a longer time. Actually, why do you need that? Any use case for min 3 seconds loading?Manwell
@Sambhav.K Because I want to load my video fastly on startup time. So, I added minimum value there. Anything else I'm doing?Maiga
T
6
  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
); 
Teferi answered 18/5, 2022 at 17:8 Comment(10)
sir, how can I get bitrate of my video?Maiga
You can get the bitrate of your video by using ExoPlayer.TrackInfo.bitrate ``` int videoBitrate = exoPlayer.getTrackInfo().bitrate; ``` Note: If you are using ExoPlayer.EventListener to listen for events, make sure you don't have a lot of logic in your event listeners. Because they are called on the main thread, they can slow down the playback if they take too long.Teferi
I tried your code but some of the code not found in the Exoplayer library like these are DEFAULT MAX LOADING MS , DEFAULT MIN ELAPSED MS BEFORE STOPPING, not found in exoplayer library. I tried 2nd method but not found good result. I'm testing my video in my Exoplayer and Chrome Browser player. Chrome browser player plays my video 4X faster then my app Exoplayer? And I'm playing my same video and same time. Someone also asked this question in exoplayer git but not got good answer or result see their question github.com/google/ExoPlayer/issues/6484 this same issue causing with me!Maiga
I just edited the code for the 1st method, it may fix itTeferi
I appreciate your effort and am thankful for it. But I could not find the result. I think this is a bug in Exoplaye?Maiga
I think thats very possibleTeferi
yeah, the same video I played with 1080px on youtube by uploading and playing without loading and I also played my video on Chrome Browser by uploading on my server and it plays after loading ~0.5 seconds, and when the same video play in-app it play after 4-6 second and buffering also in playing time???Maiga
That is so weirdTeferi
It's working very fine(dep. update of Exo or any bug fixing). But your answer is helpful in improving playing speed and video loading speed. Thank youMaiga
So how did you fix it ?? Can you describe more ?Squad
M
0

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

int MIN_PLAYBACK_RESUME_BUFFER = 1500;
int MIN_PLAYBACK_START_BUFFER = 500;
Mullens answered 17/5, 2022 at 15:7 Comment(1)
Thanks for your answer. I tried to make them 0 but the video is buffering every time means buffering and playing buffering and playing. Do you have any other solutions or changes?Maiga
W
-1

What worked for me was this:

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

as per @Carter McKay answer just changed the MAX_BUFFER_DURATION.

While answered 23/1, 2023 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.