android 有时候视频缓冲非常慢exoplayer?

3okqufwl  于 2023-01-24  发布在  Android
关注(0)|答案(3)|浏览(822)

我不知道为什么,但是有时候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 issue github这个相同的问题导致了我!
有人知道为什么会这样吗?你的回答对我有帮助。

sd2nnvve

sd2nnvve1#

1.确保您使用的是最新版本的Exoplayer。在撰写本文时,它是2. 10. 4。
1.尝试增加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.请尝试使用其他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);

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);
2vuwiymt

2vuwiymt2#

将以下设置为0 -〉测试行为-〉根据需要进行调整

int MIN_PLAYBACK_RESUME_BUFFER = 1500;
int MIN_PLAYBACK_START_BUFFER = 500;
g6baxovj

g6baxovj3#

对我起作用的是:

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的回答,刚刚更改了最大缓冲持续时间。

相关问题