fix(android): improve and backBufferDurationMs. mainly let exoplayer manage the prop (#3619)
BREAKING CHANGE: move backBufferDurationMs from root props to bufferConfig
This commit is contained in:
parent
24c1aab3f5
commit
f10511d953
@ -191,6 +191,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
|
private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
|
||||||
private int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
|
private int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
|
||||||
private int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
|
private int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
|
||||||
|
private int backBufferDurationMs = DefaultLoadControl.DEFAULT_BACK_BUFFER_DURATION_MS;
|
||||||
private double maxHeapAllocationPercent = ReactExoplayerView.DEFAULT_MAX_HEAP_ALLOCATION_PERCENT;
|
private double maxHeapAllocationPercent = ReactExoplayerView.DEFAULT_MAX_HEAP_ALLOCATION_PERCENT;
|
||||||
private double minBackBufferMemoryReservePercent = ReactExoplayerView.DEFAULT_MIN_BACK_BUFFER_MEMORY_RESERVE;
|
private double minBackBufferMemoryReservePercent = ReactExoplayerView.DEFAULT_MIN_BACK_BUFFER_MEMORY_RESERVE;
|
||||||
private double minBufferMemoryReservePercent = ReactExoplayerView.DEFAULT_MIN_BUFFER_MEMORY_RESERVE;
|
private double minBufferMemoryReservePercent = ReactExoplayerView.DEFAULT_MIN_BUFFER_MEMORY_RESERVE;
|
||||||
@ -198,7 +199,6 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
private Runnable mainRunnable;
|
private Runnable mainRunnable;
|
||||||
|
|
||||||
// Props from React
|
// Props from React
|
||||||
private int backBufferDurationMs = DefaultLoadControl.DEFAULT_BACK_BUFFER_DURATION_MS;
|
|
||||||
private Uri srcUri;
|
private Uri srcUri;
|
||||||
private long startPositionMs = -1;
|
private long startPositionMs = -1;
|
||||||
private long cropStartMs = -1;
|
private long cropStartMs = -1;
|
||||||
@ -1944,20 +1944,6 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
exoPlayerView.setFocusable(this.focusable);
|
exoPlayerView.setFocusable(this.focusable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackBufferDurationMs(int backBufferDurationMs) {
|
|
||||||
Runtime runtime = Runtime.getRuntime();
|
|
||||||
long usedMemory = runtime.totalMemory() - runtime.freeMemory();
|
|
||||||
long freeMemory = runtime.maxMemory() - usedMemory;
|
|
||||||
long reserveMemory = (long)minBackBufferMemoryReservePercent * runtime.maxMemory();
|
|
||||||
if (reserveMemory > freeMemory) {
|
|
||||||
// We don't have enough memory in reserve so we will
|
|
||||||
DebugLog.w("ExoPlayer Warning", "Not enough reserve memory, setting back buffer to 0ms to reduce memory pressure!");
|
|
||||||
this.backBufferDurationMs = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.backBufferDurationMs = backBufferDurationMs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContentStartTime(int contentStartTime) {
|
public void setContentStartTime(int contentStartTime) {
|
||||||
this.contentStartTime = contentStartTime;
|
this.contentStartTime = contentStartTime;
|
||||||
}
|
}
|
||||||
@ -2043,7 +2029,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
exoPlayerView.setHideShutterView(hideShutterView);
|
exoPlayerView.setHideShutterView(hideShutterView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBufferConfig(int newMinBufferMs, int newMaxBufferMs, int newBufferForPlaybackMs, int newBufferForPlaybackAfterRebufferMs, double newMaxHeapAllocationPercent, double newMinBackBufferMemoryReservePercent, double newMinBufferMemoryReservePercent) {
|
public void setBufferConfig(int newMinBufferMs, int newMaxBufferMs, int newBufferForPlaybackMs, int newBufferForPlaybackAfterRebufferMs, double newMaxHeapAllocationPercent, double newMinBackBufferMemoryReservePercent, double newMinBufferMemoryReservePercent, int newBackBufferDurationMs) {
|
||||||
minBufferMs = newMinBufferMs;
|
minBufferMs = newMinBufferMs;
|
||||||
maxBufferMs = newMaxBufferMs;
|
maxBufferMs = newMaxBufferMs;
|
||||||
bufferForPlaybackMs = newBufferForPlaybackMs;
|
bufferForPlaybackMs = newBufferForPlaybackMs;
|
||||||
@ -2051,6 +2037,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
maxHeapAllocationPercent = newMaxHeapAllocationPercent;
|
maxHeapAllocationPercent = newMaxHeapAllocationPercent;
|
||||||
minBackBufferMemoryReservePercent = newMinBackBufferMemoryReservePercent;
|
minBackBufferMemoryReservePercent = newMinBackBufferMemoryReservePercent;
|
||||||
minBufferMemoryReservePercent = newMinBufferMemoryReservePercent;
|
minBufferMemoryReservePercent = newMinBufferMemoryReservePercent;
|
||||||
|
backBufferDurationMs = newBackBufferDurationMs;
|
||||||
releasePlayer();
|
releasePlayer();
|
||||||
initializePlayer();
|
initializePlayer();
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
private static final String PROP_MUTED = "muted";
|
private static final String PROP_MUTED = "muted";
|
||||||
private static final String PROP_AUDIO_OUTPUT = "audioOutput";
|
private static final String PROP_AUDIO_OUTPUT = "audioOutput";
|
||||||
private static final String PROP_VOLUME = "volume";
|
private static final String PROP_VOLUME = "volume";
|
||||||
private static final String PROP_BACK_BUFFER_DURATION_MS = "backBufferDurationMs";
|
|
||||||
private static final String PROP_BUFFER_CONFIG = "bufferConfig";
|
private static final String PROP_BUFFER_CONFIG = "bufferConfig";
|
||||||
private static final String PROP_BUFFER_CONFIG_MIN_BUFFER_MS = "minBufferMs";
|
private static final String PROP_BUFFER_CONFIG_MIN_BUFFER_MS = "minBufferMs";
|
||||||
private static final String PROP_BUFFER_CONFIG_MAX_BUFFER_MS = "maxBufferMs";
|
private static final String PROP_BUFFER_CONFIG_MAX_BUFFER_MS = "maxBufferMs";
|
||||||
@ -67,6 +66,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
private static final String PROP_BUFFER_CONFIG_MAX_HEAP_ALLOCATION_PERCENT = "maxHeapAllocationPercent";
|
private static final String PROP_BUFFER_CONFIG_MAX_HEAP_ALLOCATION_PERCENT = "maxHeapAllocationPercent";
|
||||||
private static final String PROP_BUFFER_CONFIG_MIN_BACK_BUFFER_MEMORY_RESERVE_PERCENT = "minBackBufferMemoryReservePercent";
|
private static final String PROP_BUFFER_CONFIG_MIN_BACK_BUFFER_MEMORY_RESERVE_PERCENT = "minBackBufferMemoryReservePercent";
|
||||||
private static final String PROP_BUFFER_CONFIG_MIN_BUFFER_MEMORY_RESERVE_PERCENT = "minBufferMemoryReservePercent";
|
private static final String PROP_BUFFER_CONFIG_MIN_BUFFER_MEMORY_RESERVE_PERCENT = "minBufferMemoryReservePercent";
|
||||||
|
private static final String PROP_BUFFER_CONFIG_BACK_BUFFER_DURATION_MS = "backBufferDurationMs";
|
||||||
private static final String PROP_PREVENTS_DISPLAY_SLEEP_DURING_VIDEO_PLAYBACK = "preventsDisplaySleepDuringVideoPlayback";
|
private static final String PROP_PREVENTS_DISPLAY_SLEEP_DURING_VIDEO_PLAYBACK = "preventsDisplaySleepDuringVideoPlayback";
|
||||||
private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
|
private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
|
||||||
private static final String PROP_REPORT_BANDWIDTH = "reportBandwidth";
|
private static final String PROP_REPORT_BANDWIDTH = "reportBandwidth";
|
||||||
@ -350,11 +350,6 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
videoView.setFocusable(focusable);
|
videoView.setFocusable(focusable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactProp(name = PROP_BACK_BUFFER_DURATION_MS, defaultInt = 0)
|
|
||||||
public void setBackBufferDurationMs(final ReactExoplayerView videoView, final int backBufferDurationMs) {
|
|
||||||
videoView.setBackBufferDurationMs(backBufferDurationMs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReactProp(name = PROP_CONTENT_START_TIME, defaultInt = -1)
|
@ReactProp(name = PROP_CONTENT_START_TIME, defaultInt = -1)
|
||||||
public void setContentStartTime(final ReactExoplayerView videoView, final int contentStartTime) {
|
public void setContentStartTime(final ReactExoplayerView videoView, final int contentStartTime) {
|
||||||
videoView.setContentStartTime(contentStartTime);
|
videoView.setContentStartTime(contentStartTime);
|
||||||
@ -411,6 +406,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
|
int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
|
||||||
int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
|
int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
|
||||||
int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
|
int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
|
||||||
|
int backBufferDurationMs = DefaultLoadControl.DEFAULT_BACK_BUFFER_DURATION_MS;
|
||||||
double maxHeapAllocationPercent = ReactExoplayerView.DEFAULT_MAX_HEAP_ALLOCATION_PERCENT;
|
double maxHeapAllocationPercent = ReactExoplayerView.DEFAULT_MAX_HEAP_ALLOCATION_PERCENT;
|
||||||
double minBackBufferMemoryReservePercent = ReactExoplayerView.DEFAULT_MIN_BACK_BUFFER_MEMORY_RESERVE;
|
double minBackBufferMemoryReservePercent = ReactExoplayerView.DEFAULT_MIN_BACK_BUFFER_MEMORY_RESERVE;
|
||||||
double minBufferMemoryReservePercent = ReactExoplayerView.DEFAULT_MIN_BUFFER_MEMORY_RESERVE;
|
double minBufferMemoryReservePercent = ReactExoplayerView.DEFAULT_MIN_BUFFER_MEMORY_RESERVE;
|
||||||
@ -423,7 +419,8 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
maxHeapAllocationPercent = ReactBridgeUtils.safeGetDouble(bufferConfig, PROP_BUFFER_CONFIG_MAX_HEAP_ALLOCATION_PERCENT, maxHeapAllocationPercent);
|
maxHeapAllocationPercent = ReactBridgeUtils.safeGetDouble(bufferConfig, PROP_BUFFER_CONFIG_MAX_HEAP_ALLOCATION_PERCENT, maxHeapAllocationPercent);
|
||||||
minBackBufferMemoryReservePercent = ReactBridgeUtils.safeGetDouble(bufferConfig, PROP_BUFFER_CONFIG_MIN_BACK_BUFFER_MEMORY_RESERVE_PERCENT, minBackBufferMemoryReservePercent);
|
minBackBufferMemoryReservePercent = ReactBridgeUtils.safeGetDouble(bufferConfig, PROP_BUFFER_CONFIG_MIN_BACK_BUFFER_MEMORY_RESERVE_PERCENT, minBackBufferMemoryReservePercent);
|
||||||
minBufferMemoryReservePercent = ReactBridgeUtils.safeGetDouble(bufferConfig, PROP_BUFFER_CONFIG_MIN_BUFFER_MEMORY_RESERVE_PERCENT, minBufferMemoryReservePercent);
|
minBufferMemoryReservePercent = ReactBridgeUtils.safeGetDouble(bufferConfig, PROP_BUFFER_CONFIG_MIN_BUFFER_MEMORY_RESERVE_PERCENT, minBufferMemoryReservePercent);
|
||||||
videoView.setBufferConfig(minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs, maxHeapAllocationPercent, minBackBufferMemoryReservePercent, minBufferMemoryReservePercent);
|
backBufferDurationMs = ReactBridgeUtils.safeGetInt(bufferConfig, PROP_BUFFER_CONFIG_BACK_BUFFER_DURATION_MS, backBufferDurationMs);
|
||||||
|
videoView.setBufferConfig(minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs, maxHeapAllocationPercent, minBackBufferMemoryReservePercent, minBufferMemoryReservePercent, backBufferDurationMs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,12 +58,6 @@ A Boolean value that indicates whether the player should automatically delay pla
|
|||||||
- **false** - Immediately starts playback
|
- **false** - Immediately starts playback
|
||||||
- **true (default)** - Delays playback in order to minimize stalling
|
- **true (default)** - Delays playback in order to minimize stalling
|
||||||
|
|
||||||
### `backBufferDurationMs`
|
|
||||||
|
|
||||||
<PlatformsList types={['Android']} />
|
|
||||||
|
|
||||||
The number of milliseconds of buffer to keep before the current position. This allows rewinding without rebuffering within that duration.
|
|
||||||
|
|
||||||
### `bufferConfig`
|
### `bufferConfig`
|
||||||
|
|
||||||
<PlatformsList types={['Android']} />
|
<PlatformsList types={['Android']} />
|
||||||
@ -76,11 +70,11 @@ Adjust the buffer settings. This prop takes an object with one or more of the pr
|
|||||||
| maxBufferMs | number | The default maximum duration of media that the player will attempt to buffer, in milliseconds. |
|
| maxBufferMs | number | The default maximum duration of media that the player will attempt to buffer, in milliseconds. |
|
||||||
| bufferForPlaybackMs | number | The default duration of media that must be buffered for playback to start or resume following a user action such as a seek, in milliseconds. |
|
| bufferForPlaybackMs | number | The default duration of media that must be buffered for playback to start or resume following a user action such as a seek, in milliseconds. |
|
||||||
| bufferForPlaybackAfterRebufferMs | number | The default duration of media that must be buffered for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by buffer depletion rather than a user action. |
|
| bufferForPlaybackAfterRebufferMs | number | The default duration of media that must be buffered for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by buffer depletion rather than a user action. |
|
||||||
|
| backBufferDurationMs | number | The number of milliseconds of buffer to keep before the current position. This allows rewinding without rebuffering within that duration. |
|
||||||
| maxHeapAllocationPercent | number | The percentage of available heap that the video can use to buffer, between 0 and 1 |
|
| maxHeapAllocationPercent | number | The percentage of available heap that the video can use to buffer, between 0 and 1 |
|
||||||
| minBackBufferMemoryReservePercent | number | The percentage of available app memory at which during startup the back buffer will be disabled, between 0 and 1 |
|
| minBackBufferMemoryReservePercent | number | The percentage of available app memory at which during startup the back buffer will be disabled, between 0 and 1 |
|
||||||
| minBufferMemoryReservePercent | number | The percentage of available app memory to keep in reserve that prevents buffer from using it, between 0 and 1 |
|
| minBufferMemoryReservePercent | number | The percentage of available app memory to keep in reserve that prevents buffer from using it, between 0 and 1 |
|
||||||
|
|
||||||
This prop should only be set when you are setting the source, changing it after the media is loaded will cause it to be reloaded.
|
|
||||||
|
|
||||||
Example with default values:
|
Example with default values:
|
||||||
|
|
||||||
@ -89,7 +83,8 @@ bufferConfig={{
|
|||||||
minBufferMs: 15000,
|
minBufferMs: 15000,
|
||||||
maxBufferMs: 50000,
|
maxBufferMs: 50000,
|
||||||
bufferForPlaybackMs: 2500,
|
bufferForPlaybackMs: 2500,
|
||||||
bufferForPlaybackAfterRebufferMs: 5000
|
bufferForPlaybackAfterRebufferMs: 5000,
|
||||||
|
backBufferDurationMs: 120000,
|
||||||
}}
|
}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -108,6 +108,7 @@ type BufferConfig = Readonly<{
|
|||||||
bufferForPlaybackMs?: Float;
|
bufferForPlaybackMs?: Float;
|
||||||
bufferForPlaybackAfterRebufferMs?: Float;
|
bufferForPlaybackAfterRebufferMs?: Float;
|
||||||
maxHeapAllocationPercent?: Float;
|
maxHeapAllocationPercent?: Float;
|
||||||
|
backBufferDurationMs?: Float; // Android
|
||||||
minBackBufferMemoryReservePercent?: Float;
|
minBackBufferMemoryReservePercent?: Float;
|
||||||
minBufferMemoryReservePercent?: Float;
|
minBufferMemoryReservePercent?: Float;
|
||||||
}>;
|
}>;
|
||||||
@ -484,7 +485,6 @@ export interface VideoNativeProps extends ViewProps {
|
|||||||
localSourceEncryptionKeyScheme?: string;
|
localSourceEncryptionKeyScheme?: string;
|
||||||
debug?: DebugConfig;
|
debug?: DebugConfig;
|
||||||
|
|
||||||
backBufferDurationMs?: Int32; // Android
|
|
||||||
bufferConfig?: BufferConfig; // Android
|
bufferConfig?: BufferConfig; // Android
|
||||||
contentStartTime?: Int32; // Android
|
contentStartTime?: Int32; // Android
|
||||||
currentPlaybackTime?: Double; // Android
|
currentPlaybackTime?: Double; // Android
|
||||||
|
@ -68,6 +68,7 @@ export type BufferConfig = {
|
|||||||
maxBufferMs?: number;
|
maxBufferMs?: number;
|
||||||
bufferForPlaybackMs?: number;
|
bufferForPlaybackMs?: number;
|
||||||
bufferForPlaybackAfterRebufferMs?: number;
|
bufferForPlaybackAfterRebufferMs?: number;
|
||||||
|
backBufferDurationMs?: number; // Android
|
||||||
maxHeapAllocationPercent?: number;
|
maxHeapAllocationPercent?: number;
|
||||||
minBackBufferMemoryReservePercent?: number;
|
minBackBufferMemoryReservePercent?: number;
|
||||||
minBufferMemoryReservePercent?: number;
|
minBufferMemoryReservePercent?: number;
|
||||||
@ -188,7 +189,6 @@ export interface ReactVideoProps extends ReactVideoEvents, ViewProps {
|
|||||||
audioOnly?: boolean;
|
audioOnly?: boolean;
|
||||||
audioOutput?: AudioOutput; // Mobile
|
audioOutput?: AudioOutput; // Mobile
|
||||||
automaticallyWaitsToMinimizeStalling?: boolean; // iOS
|
automaticallyWaitsToMinimizeStalling?: boolean; // iOS
|
||||||
backBufferDurationMs?: number; // Android
|
|
||||||
bufferConfig?: BufferConfig; // Android
|
bufferConfig?: BufferConfig; // Android
|
||||||
chapters?: Chapters[]; // iOS
|
chapters?: Chapters[]; // iOS
|
||||||
contentStartTime?: number; // Android
|
contentStartTime?: number; // Android
|
||||||
|
Loading…
Reference in New Issue
Block a user