VEX-6030-reduce-buffer-size-based-on-heap
This commit is contained in:
parent
e27baeb065
commit
0ab7ff476b
@ -2,6 +2,7 @@ package com.brentvatne.exoplayer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
@ -401,6 +402,7 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
|
||||
private class RNVLoadControl extends DefaultLoadControl {
|
||||
private int availableHeapInBytes = 0;
|
||||
public RNVLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBufferMs, int bufferForPlaybackMs, int bufferForPlaybackAfterRebufferMs, int targetBufferBytes, boolean prioritizeTimeOverSizeThresholds, int backBufferDurationMs, boolean retainBackBufferFromKeyframe) {
|
||||
super(allocator,
|
||||
minBufferMs,
|
||||
@ -411,10 +413,18 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
prioritizeTimeOverSizeThresholds,
|
||||
backBufferDurationMs,
|
||||
retainBackBufferFromKeyframe);
|
||||
if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.N) {
|
||||
ActivityManager activityManager = (ActivityManager) themedReactContext.getSystemService(themedReactContext.ACTIVITY_SERVICE);
|
||||
availableHeapInBytes = activityManager.getMemoryClass() / 2 * 1024 * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
|
||||
int loadedBytes = getAllocator().getTotalBytesAllocated();
|
||||
if (availableHeapInBytes > 0 && loadedBytes >= availableHeapInBytes) {
|
||||
return false;
|
||||
}
|
||||
if (ReactExoplayerView.this.disableBuffering) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user